On Tuesday, 5 August 2014 at 19:21:44 UTC, Philippe Sigaud via
Digitalmars-d-learn wrote:
Some range which takes an at compile time known number of
elements from an
input range and provides opIndex seems perfect to me, but as
far as I know
there's no such thing in Phobos.
There is chunks:
http://dlang.org/phobos/std_range.html#chunks
Yea, but that won't work for forward ranges. It only provides
opIndex if the underlying range provides it. Since the chunk size
is a runtime parameter it can't implement opIndex efficiently for
non-random access ranges.
staticChunks was a bit of a misnomer. staticTake would be a
better name. The range would contains a static array and pops
that number of elements from the input range. Then, opIndex can
easily be defined.