On Monday, 11 August 2014 at 03:29:56 UTC, Andrei Alexandrescu
wrote:
[...] can be implemented generically for ranges that offer
front as a reference:
bool sameFront(R1, R2)(R1 r1, R2 r2) {
return &r1.front == &r2.front;
}
This doesn't work for ranges that visit the same element twice,
e.g.
cycle(arr).take(arr.length + 1)
[0, 0].map!(i => arr[i])
I suspect most ranges will have to implement the sameFront
primitive manually, usually forwarding to the underlying range.
Related: most mutating algorithms won't work for these kinds of
ranges, as we usually presume lvalue ranges never visit the same
lvalue twice. Perhaps this needs to be mentioned on affected
algorithms?