Last active
December 15, 2015 09:19
-
-
Save yurial/5237710 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef EXT_TOKH | |
#define EXT_TOKH | |
#include <string> | |
#include <vector> | |
#include <set> | |
namespace ext | |
{ | |
template <class C/*ontainer*/> | |
class basetok: | |
public C | |
{ | |
public: | |
typedef C container_t; | |
template <class D/*elim*/> | |
basetok(const D& delim, const typename C::value_type& str); | |
}; | |
template <class C/*ontainer*/> | |
template <class D/*elim*/> | |
basetok<C>::basetok(const D& delim, const typename C::value_type& str) | |
{ | |
for(size_t begin = 0, pos = 0; C::value_type::npos != pos; begin = pos + 1) | |
{ | |
pos = str.find( delim, begin ); | |
std::insert_iterator<C>( *this, C::end() ) = str.substr( begin, pos - begin ); | |
} | |
} | |
template <class S = std::string> | |
class strtok: | |
public basetok<std::vector<S> > | |
{ | |
public: | |
template <class D/*elim*/> | |
inline strtok(const D& delim, const S& str): basetok<std::vector<S> >( delim, str ) {} | |
}; | |
template <class S = std::string> | |
class uniqtok: | |
public basetok<std::set<S> > | |
{ | |
public: | |
template <class D/*elim*/> | |
inline uniqtok(const D& delim, const S& str): basetok<std::set<S> >( delim, str ) {} | |
}; | |
} //namespace ext | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment