Boost logo

Boost Users :

Subject: Re: [Boost-users] tokenize string delimiter
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2010-02-10 19:57:41


On Feb 9, 2010, at 5:58 PM, Matthias Vallentin wrote:

> On Tue, Feb 09, 2010 at 02:00:10PM +0530, Lloyd wrote:
>> Is it possibleto tokenize a string based on a string delimiter?
>
> Let str be the string to split and delim your delimiter. Then,
>
> std::vector<std::string> result;
> boost::iter_split(result, str, boost::first_finder(delim));
>
> Or case insensitive:
>
> std::vector<std::string> result;
> boost::iter_split(result, str,
> boost::first_finder(delim, boost::is_iequal()));

Can anyone tell me why iter_split (and split, etc) requires a vector<string> to hold the results? (or, more generally, a container)
Is there some technical reason why it doesn't take an output iterator as a parameter, so it could be called like this?

        std::vector<std::string> result;
        boost::iter_split ( std::back_inserter<string> (result), str, boost::first_finder(delim));
or even:
        boost::iter_split ( std::ostream_iterator<std::string>(std::cout, ", "), str, boost::first_finder(delim));
        
(thereby removing the (fixed) link between "iter_split" and "std::vector<std::string>")

-- Marshall


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