opCmp and opEquals woes

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 25 00:31:07 PDT 2014


On Friday, 25 July 2014 at 07:21:11 UTC, Daniel Murphy wrote:
> "Walter Bright"  wrote in message 
> news:lqsunn$2ke5$1 at digitalmars.com...
>
>> Determining an ordering can sometimes be more expensive. It 
>> is, after all, asking for more information.
>
> It could also be significantly cheaper, if only a subset of 
> fields need to be compared.

If that's the case, then the default opEquals isn't correct, and 
the programmer should have already defined opEquals. If they 
didn't, then their code is broken, and I see no reason to 
penalize the folks who wrote correct code just to fix someone 
else's broken code by then defining opEquals in terms of opCmp.

- Jonathan M Davis


More information about the Digitalmars-d mailing list