Bug 21191 – min should be stable: when in doubt, return the first argument
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-23T01:28:02Z
Last change time
2020-08-28T06:19:46Z
Keywords
pull
Assigned to
No Owner
Creator
Andrei Alexandrescu
Comments
Comment #0 by andrei — 2020-08-23T01:28:02Z
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.
Comment #1 by dlang-bot — 2020-08-23T01:29:26Z
@andralex updated dlang/phobos pull request #7605 "min must be stable" fixing this issue:
- Fix Issue 21191 - min should be stable: when in doubt, return the first argument
https://github.com/dlang/phobos/pull/7605
Comment #2 by dlang-bot — 2020-08-28T06:19:46Z
dlang/phobos pull request #7605 "min must be stable" was merged into master:
- beb200d546b2f15b8c9620c5c520fd6ba584fb79 by Andrei Alexandrescu:
Fix Issue 21191 - min should be stable: when in doubt, return the first argument
https://github.com/dlang/phobos/pull/7605