C ++ range iterator algorithm to collect result

I wrote a function to collect the result of a range of iterator boost. There he is:

template<typename Output, typename SinglePassRange>
Output collect(const SinglePassRange & rng)
{
    Output r;
    boost::range::copy(rng, std::inserter(r, boost::begin(r)));
    return r;
}

This is pretty handy:

return collect<std::vector<int>>(ints | filtered(even) | transformed(add1));

It looks like it really should already exist, but I could not find it. (Not to mention that it would be nice to "infer" the return type in some way, which would be a more likely sign in the standard implementation.)

Does anyone know of a function that behaves like this?

+3
source share

All Articles