Why is mostNegative!T not of type T?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 17 20:58:20 UTC 2021


On 10/17/21 4:32 PM, Steven Schveighoffer wrote:
> 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 
> 
> 
> ;)

Before looking: I bet it was me.

After looking: woe is me.



More information about the Digitalmars-d mailing list