[Issue 23422] uniq backward iteration has different elements to forward iteration

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 17 10:52:54 UTC 2022


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

--- Comment #1 from FeepingCreature <default_357-line at yahoo.de> ---
Update: The actual issue is that uniq backwards iteration contains different
elements than its forwards iteration:

import std;

void main() {
    auto range = [1, 2].uniq!"true";
    writefln!"forward %s, backward %s"(range.retro.array.retro.array,
range.array);
    assert(range.retro.array.retro.array == range.array);
}

I understand why uniq would want to work that way, but it should arguably not
be allowed to:
https://dlang.org/library/std/range/primitives/is_bidirectional_range.html says
that `back` has to return "the last element in the range". It's undefined what
exactly this means, but it's certainly questionable that "back" is an element
that doesn't appear in the forward iteration order at all.

--


More information about the Digitalmars-d-bugs mailing list