WAT: opCmp and opEquals woes

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 23 11:49:58 PDT 2014


On 7/23/14, 11:09 AM, Dicebot wrote:
> On Wednesday, 23 July 2014 at 17:15:12 UTC, Ary Borenszweig wrote:
>> Imagine you have a list of integers and strings denoting integers: [1,
>> "2", 100, "38"]. Now you want to sort them according to their numeric
>> value. Of course, 1 and "1" would have the same order. However, 1 and
>> "1" are different, so "==" would give false, while 1.opCmp("1") would
>> give 0.
>>
>> Equality and comparison are different. opCmp is used for sorting
>> objects, which has nothing to do with equality. Inferring equality
>> from opCmp is wrong in my opinion.
>
> Well this is why you can actually override those :) I think automatic
> opCmd -> opEqual generation covers vast majority of use cases and as
> such will have a vary good effort / decreased annoyance ratio.

I'd say let's leave things as they are. opEquals may need to do less 
work than opCmp, and it often sees intensive use. -- Andrei


More information about the Digitalmars-d mailing list