Open gbeck75 opened 7 months ago
generate
results in an input range.
iota
results in a random access range.
chunk_by
requires a forward range.
Thank 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.
The following code fails to compile but works as expected if I use iota() instead of generate()
Is this to be expected? How can I use views::chunk_by with views::generate ?