Overloading relational operators separately; thoughts?

Matthias Bentrup via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 28 02:48:48 PDT 2016


On Wednesday, 28 September 2016 at 04:02:59 UTC, Walter Bright 
wrote:
> The limitations are deliberate based on the idea that 
> comparison operators need to be consistent and predictable, and 
> should have a close relationship to the mathematical meaning of 
> the operators.

In Mathematics the comparison operators are also commonly used 
for semi orders, which cannot be implemented by opCmp, because 
opCmp has no way to indicate that two values are incomparable.

Interestingly the floating point types are semi ordered (due to 
NaNs), and for those D has some (non-overridable and deprecated) 
operators like !<, which would be easily extendable to any semi 
order, whereas the suggested replacement (i.e. test for NaNs 
manually) works only on floats.



More information about the Digitalmars-d mailing list