The following code fails to compile but works as expected if I use iota() instead of generate()
// auto v = views::iota(10,20);
auto v = views::generate(
[i=10u] () mutable {
return i++;
}) | views::take(10);
auto r = v | views::chunk_by(
[](auto a, auto) {
return a == 15;
})Is this to be expected? How can I use views::chunk_by with views::generate ?
Activity
5Thank you! And how can I "generate" a forward range?
Generating a forward range would mean having a regular invocable that returns the same value based on an index.
You can generate a forward range with iota(0) | transform(generate_function).
Unfortunately I only have an input range.
It seems the question should really be why chunk_by needs a forward range? In the example it should be possible to chunk the input range in a single pass, is there something like chunk_by which works on an input range?
I'm looking at the C++ standard library implementation.
The reason seems to be that the implementation needs two iterators into the range.
The iterator's value type is a subrange: https://eel.is/c++draft/range.chunk.by#iter.
You can probably write a version that works for input ranges.
generateresults in an input range.iotaresults in a random access range.chunk_byrequires a forward range.