[Issue 21191] New: min should be stable: when in doubt, return the first argument
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Aug 23 01:28:02 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21191
Issue ID: 21191
Summary: min should be stable: when in doubt, return the first
argument
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: andrei at erdani.com
This should work:
@safe unittest
{
import std.algorithm;
assert(min(1.0, double.nan) == 1.0);
assert(min(double.nan, 1.0) is double.nan);
static struct A {
int x;
string y;
int opCmp(A a) { return int(x > a.x) - int(x < a.x); }
}
assert(min(A(1, "first"), A(1, "second")) == A(1, "first"));
}
In other words, min should return its first argument unless it makes a positive
determination that the second argument "deserves" to be returned instead.
--
More information about the Digitalmars-d-bugs
mailing list