I have written a function to collect the result of a boost iterator range. Here it 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;
}
It is rather convenient:
return collect<std::vector<int>>(ints | filtered(even) | transformed(add1));
This seems like something that really ought to exist already, but I could not find it. (Not to mention it would be nice to "deduce" the return type somehow, which would be a feature more likely found in a standard implementation.)
Does anyone know of a function that behaves like this?