[Issue 21249] New: clamp() is not stable and is not constrained
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Sep 15 15:56:42 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21249
Issue ID: 21249
Summary: clamp() is not stable and is not constrained
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
For elaborate objects defining comparison, clamp() should return the leftmost
object unless it falls outside the limits established by the other two
parameters.
Consider:
struct A {
int x, y;
int opCmp(ref const A rhs) const { return (x > rhs.x) - (x < rhs.x); }
}
A x, lo, hi;
x.y = 42;
assert(x.clamp(lo, hi).y == 42);
Also, clamp() needs to be constrained appropriately.
--
More information about the Digitalmars-d-bugs
mailing list