util.h 951 Bytes
#ifndef UTIL_H
#define UTIL_H

#include <string>

template < class ContainerT >
void tokenize(const std::string& str, ContainerT& tokens,
							const std::string& delimiters = " ", bool trimEmpty = false)
{
	std::string::size_type pos, lastPos = 0, length = str.length();

	using value_type = typename ContainerT::value_type;
	using size_type  = typename ContainerT::size_type;

	while(lastPos < length + 1)
	{
		pos = str.find_first_of(delimiters, lastPos);
		if(pos == std::string::npos)
		{
			pos = length;
		}

		if(pos != lastPos || !trimEmpty)
			tokens.push_back(value_type(str.data()+lastPos,
																	(size_type)pos-lastPos ));

		lastPos = pos + 1;
	}
}

template <class T>
std::pair<T,T> minmax(T tab[],unsigned int size){
	T min = tab[0];
	T max = tab[0];
	for(unsigned int i=0; i < size; i++){
		min = (min > tab[i]) ? tab[i] : min;
		max = (max < tab[i]) ? tab[i] : max;
	}
	return std::pair<T,T>(min,max);
}

#endif // UTIL_H