D operator overloading. Why that way?

bearophile bearophileHUGS at lycos.com
Wed Sep 19 07:58:17 PDT 2012


Hauleth:

> Is there any reason to allow overload `op=`? IMHO it should be 
> left illegal and should be interpreted always as `a = a op b`. 
> It will be simpler and less confusing.

The increase of complexity and confusion is small.


> Also why `opEquals` is independent from `opCmp`?

A Complex number defines equality but not comparisons:
https://raw.github.com/D-Programming-Language/phobos/master/std/complex.d

Sometimes computing equality is faster than comparisons, so
better have both.


> Once again `opEquals` should be removed and equality will be 
> provided by `opCmp() == 0`.

I'd like the opposite: more freedom to be able to define "<" but
not "<=".

Bye,
bearophile


More information about the Digitalmars-d mailing list