WAT: opCmp and opEquals woes

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 25 13:07:07 PDT 2014


On 2014-07-25 20:56, Jonathan M Davis wrote:

> opEquals will now be used for AA keys, not opCmp.

Well, yes. But that was not the case when the code was written. In that 
case it was to correct to defined opCmp.

> That's why git master
> generates errors when you have a struct which defines opCmp and not
> opEquals, and you try and use it as an AA key. It was done on the theory
> that your opEquals and opCmp might not match (which would be buggy code
> to begin with, so it would be forcing everyone to change their code just
> because someone might have gotten their opEquals and opCmp wrong).
>
> If we keep the same behavior as 2.065 but still change the AAs to use
> opEquals, then there's no need to define opEquals unless the type was
> buggy and defined opCmp in a way that was inconsistent with the default
> opEquals and then didn't define one which was consistent. The code will
> continue to work.
>
> H.S. Teoh wants to change the default-generated opEquals to be
> equivalent to lhs.opCmp(rhs) == 0 in the case where opCmp is defined in
> order to avoid further breaking the code of folks whose code is broken
> and didn't define opEquals when opCmp didn't match the default.
>
> So, if we remove the new check for a user-defined opEquals when opCmp is
> defined, then you don't have to define opEquals. If we do what H.S. Teoh
> suggests, then you'll have to define it if you want to avoid the
> additional checks that opCmp would be doing that opEquals wouldn't do,
> but if you didn't care, then you wouldn't. If we leave it as it is in
> git master, then you'd always have to define it if you defined opCmp and
> wanted to use it as an AA key, and since opCmp was used for AA keys
> before, that means that _every_ type which didn't define opEquals but
> was used as an AA key will suddenly have to define opEquals and toHash
> and will thus now be broken. So, the current situation in git master is
> the worst all around.

That's what I'm saying. I don't understand what you're arguing for/against.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list