When does take modify the underlying iterator?
cy via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 16 15:40:29 PDT 2016
On Tuesday, 16 August 2016 at 21:13:38 UTC, Steven Schveighoffer
wrote:
> static if(isForwardRange!(typeof(iter)))
> But this may not work for any input range, since any time you
> copy the range, you are copying internal state that may cache
> an element or more.
Yes, that was the problem with SecretlyForwardRange, is that it
acts like a ForwardRange because it's implicitly copied, but
doesn't implement .save, so isForwardRange would return false.
> What we need is a take function that accepts input ranges by
> reference, so it modifies the original.
What we need is a way to split a range into two sub-ranges, the
head and the tail.
auto res = a.take(1)
auto head = res.head
a = res.tail
...or something. Like what findSplit does, but with an index
instead of a delimiter.
More information about the Digitalmars-d-learn
mailing list