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: nob...@puremagic.com Reporter: and...@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. --