[Issue 22414] New: clamp(a, b, c) should always return typeof(a)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 17 20:13:41 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22414

          Issue ID: 22414
           Summary: clamp(a, b, c) should always return typeof(a)
           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

"I will now clamp this value between this limits" has the implied contract that
you get the same type as that of the initial value.

Using min and max in the implementation of clamp is specious; in min and max
there is no "preferred" type so they use a fair method of choosing the type of
the result. In contrast, clamp is about a value that occasionally is forced to
a limit.

--


More information about the Digitalmars-d-bugs mailing list