Why is mostNegative!T not of type T?
Steven Schveighoffer
schveiguy at gmail.com
Sun Oct 17 20:32:17 UTC 2021
On 10/17/21 3:32 PM, Andrei Alexandrescu wrote:
> https://github.com/dlang/phobos/blob/master/std/traits.d#L8217
>
>
> template mostNegative(T)
> if (isNumeric!T || isSomeChar!T || isBoolean!T)
> {
> static if (is(typeof(T.min_normal)))
> enum mostNegative = -T.max;
> else static if (T.min == 0)
> enum byte mostNegative = 0;
> else
> enum mostNegative = T.min;
> }
>
> This is a breakage of the Rule of Least Astonishment: mostNegative!T for
> all unsigned types yields type byte.
You need to ask this guy why he did it:
https://github.com/dlang/phobos/commit/399fa21dea2910b2fcd525918d5227ec536c49b4#diff-b7918b17cede734a2dd4ecbf2a981d597a5978f52e02f9a3c6f53c9abd797f05R961-R966
;)
-Steve
More information about the Digitalmars-d
mailing list