September 15, 2020 [Issue 21249] New: clamp() is not stable and is not constrained | ||||
|---|---|---|---|---|
| ||||
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@puremagic.com Reporter: andrei@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. -- | ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply