[Issue 16588] New: uniq's BidirectionalRange behavior is inconsistent with its InputRange behavior

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Oct 3 16:24:49 PDT 2016


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

          Issue ID: 16588
           Summary: uniq's BidirectionalRange behavior is inconsistent
                    with its InputRange behavior
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: acehreli at yahoo.com

import std.algorithm;

struct S {
    int i;
    string s;
}

void main() {
    auto arr = [ S(1, "a"), S(1, "b"),
                 S(2, "c"), S(2, "d")];

    // Let's consider just the 'i' member for equality
    auto r = arr.uniq!((a, b) => a.i == b.i);

    assert(r.equal([S(1, "a"), S(2, "c")]));    // makes sense

    // Since there are just 2 elements, we expect the following
    assert(r.front == S(1, "a"));               // good, consistent
    assert(r.back == S(2, "c"));                // FAILS

    // Instead, the following passes but it's unexpected
    assert(r.back == S(2, "d"));
}

Bonus: uniq could take a PickStrategy template parameter so that the caller
could specify which of the unique elements of each sequence to pick, either the
first or the last.

Ali

--


More information about the Digitalmars-d-bugs mailing list