Bug 21249 – clamp() is not stable and is not constrained

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-09-15T15:56:42Z
Last change time
2020-09-15T23:20:57Z
Keywords
pull
Assigned to
No Owner
Creator
Andrei Alexandrescu

Comments

Comment #0 by andrei — 2020-09-15T15:56:42Z
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.
Comment #1 by dlang-bot — 2020-09-15T16:01:05Z
@andralex created dlang/phobos pull request #7634 "Fix Issue 21249 - clamp() is not stable and is not constrained" fixing this issue: - Fix Issue 21249 - clamp() is not stable and is not constrained https://github.com/dlang/phobos/pull/7634
Comment #2 by dlang-bot — 2020-09-15T23:20:57Z
dlang/phobos pull request #7634 "Fix Issue 21249 - clamp() is not stable and is not constrained" was merged into master: - a7d574bcba1e0104938c203615339f4fb081ed7b by Andrei Alexandrescu: Fix Issue 21249 - clamp() is not stable and is not constrained https://github.com/dlang/phobos/pull/7634