digitalmars.D.bugs - [Issue 21191] New: min should be stable: when in doubt, return the
- d-bugmail puremagic.com (30/30) Aug 22 2020 https://issues.dlang.org/show_bug.cgi?id=21191
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 puremagic.com Reporter: andrei 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. --
Aug 22 2020