Boost logo

Boost :

From: Ross Smith (ross.s_at_[hidden])
Date: 2001-07-26 17:52:46


Darin Adler wrote:
>
> vector<string> split(string [, delimiter characters]);

Returning a vector is IMHO both unnecessarily constraining and
unnecessarily inefficient. The equivalent function in my own library
looks like this:

    template <typename OutputIterator> OutputIterator
        split(const std::string& source, OutputIterator target,
            const std::string& delimiters = " /f/n/r/t")

The string fragments are written into the sequence starting with target
(which will normally be an inserter); the return value is past the end
of the output sequence (i.e. target advanced by the number of
fragments).

Typical usage:

    std::string seq("foo bar zap");
    std::vector<std::string> pieces;
    split(seq, std::back_inserter(pieces));

> string join(vector<string> [, string separator]);
> string join(start iterator, end iterator [, string separator]);

Why do you need the first when you have the second? This is the
range-vs-container debate all over again, isn't it? :-)

-- 
Ross Smith <ross.s_at_[hidden]> The Internet Group, Auckland, New Zealand
========================================================================
"Unix has always lurked provocatively in the background of the operating
system wars, like the Russian Army."                  -- Neal Stephenson

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk