Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.

Function template split

boost::algorithm::split — Split algorithm.


template<typename SequenceSequenceT, typename RangeT, typename PredicateT> 
SequenceSequenceT & 
split(SequenceSequenceT & Result, RangeT & Input, PredicateT Pred, 
token_compress_mode_type eCompress = token_compress_off);


Tokenize expression. This function is equivalent to C strtok. Input sequence is split into tokens, separated by separators. Separators are given by means of the predicate.

Each part is copied and added as a new element to the output container. Thus the result container must be able to hold copies of the matches (in a compatible structure like std::string) or a reference to it (e.g. using the iterator range class). Examples of such a container are std::vector<std::string> or std::list<boost::iterator_range<std::string::iterator>>


A container which will be searched.


A predicate to identify separators. This predicate is supposed to return true if a given element is a separator.


A container that can hold copies of references to the substrings


If eCompress argument is set to token_compress_on, adjacent separators are merged together. Otherwise, every two separators delimit a token.


A reference the result


Prior content of the result will be overwritten.

This function provides the strong exception-safety guarantee

Copyright 2002-2004 Pavol Droba