On Wed, Feb 10, 2010 at 04:57:41PM -0800, Marshall Clow wrote:
Can anyone tell me why iter_split (and split, etc) requires a vector<string> to hold the results? (or, more generally, a container)
In general, the split function receives a string as input and returns an array. (BTW, this is consistent with the majority of scripting languages, such as Ruby, Python, etc.) Because the split function a priori does not know in how many parts it will chop the input string, and it is likely to be more than one, a vector fits naturally for this task.
Is there some technical reason why it doesn't take an output iterator as a parameter, so it could be called like this?
std::vectorstd::string result; boost::iter_split ( std::back_inserter<string> (result), str, boost::first_finder(delim)); or even: boost::iter_split ( std::ostream_iteratorstd::string(std::cout, ", "), str, boost::first_finder(delim));
What you describe above is isomorphic to removing a delimiter from the string and is a separate problem. There are separate functions for this. Matthias -- Matthias Vallentin vallentin@icsi.berkeley.edu http://www.icir.org/matthias