opCmp with template type not working.

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Nov 3 13:49:04 UTC 2020


On 11/3/20 8:48 AM, Andrei Alexandrescu wrote:
> On 11/3/20 1:56 AM, ag0aep6g wrote:
>> On 03.11.20 04:07, user1234 wrote:
>>> opCmp should return a signed integer. This allows to match well with 
>>> the x86 flag register and do fast comparison with integers types (in 
>>> which case just substract rhs to lhs and you're good)
>>
>> Doing comparison by subtracting is a cute idea, but it doesn't 
>> actually work in general because of wraparound.
>>
>> Example: int.min < 1, but int.min - 1 > 0.
> 
> druntime does it for integrals smaller than int. For others, you can do:
> 
> return (a > b) - (b < a);

Ehm.

return (a > b) - (a < b);



More information about the Digitalmars-d mailing list