ranges of ranges to vector of vectors

Viewed 2088

Suppose I have a range of T's called rng. I can do

auto groups = ranges::view::group_by(rng, bin_op);

groups now being a range of ranges of T's.

I can also do this

auto groups = ranges::view::group_by(rng, bin_op) | ranges::to_vector;

to get a vector of ranges of T's. However this

auto groups = ranges::view::group_by(rng, bin_op)
            | ranges::to_vector
            | ranges::action::transform([] (auto r) { return r | ranges::to_vector; };

as well as

auto groups = ranges::view::group_by(rng, bin_op)
            | ranges::to_vector
            | ranges::action::transform([] (auto r) { return std::vector<T>{} | ranges::action::push_back; };

won't work since apparently ranges::action::transform() returns void in this case and "The result type of the function passed to action::transform must be writable back into the source range".

So how do I turn my ranges of ranges into a vector of vectors?

Note: Sorry for the bad tags, but I couldn't find a ranges/ranges-ts/ranges-v3 tag, I am not allowed to create one and couldn't use it in the title.

2 Answers
Related