WAT: opCmp and opEquals woes

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 25 21:22:26 PDT 2014


On 7/25/2014 8:41 PM, Manu via Digitalmars-d wrote:
> No, because there's no obvious reason to define opEquals if you do define opCmp
> and the opEquals would be the same.
> It seems to me, at face value, that opCmp is for full range of comparisons, and
> opEquals is for unordered types. Surely this is a reasonable conclusion to make?
>
> I don't see how you can say that a compiler generated opEquals in the presence
> of a user opCmp can reliably be correct.

You cannot say that opCmp can reliably be used for ==. Andrei provided a more 
specific example.


> It may be correct, if you're lucky, and that's the best offer you'll get.
> opCmp==0 however is practically certain to be correct, since <= and >= are
> required to work... and the api embodies the concept of equality, it would be
> very hard to write an implementation where equal was broken, but <,<=,>=,> all
> worked.

At this point, it's obvious we are going around in a circle. You ask the same 
questions over and over, and I answer them over and over. If you don't want to 
accept that equality and comparison are fundamentally different operations, I 
can only repeat saying the same things.


More information about the Digitalmars-d mailing list