Boost logo

Boost Users :

Subject: Re: [Boost-users] tokenize string delimiter
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2010-02-11 16:09:03


Matthias Vallentin wrote:
> 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.

I think what Marshall is saying is that an output iterator for example
as provided by std::back_inserter is a more natural, less limiting fit.
If the final destination is not a vector, why copy to a vector, just to
then copy from the vector to the final destination.

Jeff


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net