opCmp with template type not working.

Paul Backus snarwin at gmail.com
Wed Nov 4 15:51:04 UTC 2020

On Wednesday, 4 November 2020 at 09:01:21 UTC, Dominikus Dittes 
Scherkl wrote:
> On Tuesday, 3 November 2020 at 03:07:14 UTC, user1234 wrote:
>> opCmp should return a signed integer.
> No. opCmp should return a float, to have all 4 possible 
> comparison results available:
> greater (1)
> lower (-1)
> equal (0) and
> not comparable (NaN)
> Especially the last one is necessary if you like to have opCmp 
> defined on some not completely ordered set.

opCmp can return whatever you want, as long as it is comparable 
with 0 using the `<`, `>`, `<=`, and `>=` operators:


IMO there's no reason to use a floating-point number unless you 
specifically need partial ordering. For the common case of a 
totally-ordered type, a signed integer is fine.

More information about the Digitalmars-d mailing list