[Issue 5351] Add template mixin for Range Primitives using random access

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 1 22:57:41 UTC 2017


https://issues.dlang.org/show_bug.cgi?id=5351

--- Comment #4 from Jesse Phillips <Jesse.K.Phillips+D at gmail.com> ---
(In reply to Simen Kjaeraas from comment #3)
> The implementation above will fail for this simple case:
> 
> MyRange!int a = [1,2,3];
> a.popFront();
> assert(a[0] == a.front);
> 
> It could be made to work for ranges that support slicing, and assignment
> from the slice to the range:
> 
> void popFront() {
>     this = this[1..$];
> }

Actually this would be a good verification to add to isRandomAccessRange
because your correct that this wouldn't match for random access, but such a
behavior is fine for forward and bidirectional.

Now that being said, the confusion of having an indexable,
non-randomAccessRange with this kind of behavior would be there.

--


More information about the Digitalmars-d-bugs mailing list