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
After we undid the pull, what would be an alternative fix to this?
Comment #7 by dlang-bugzilla — 2017-05-11T10:17:57Z
(In reply to Andrei Alexandrescu from comment #6)
> After we undid the pull, what would be an alternative fix to this?
See the discussion in the revert PR.