[Issue 12255] Regression: opCmp requirement for AAs breaks code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 25 14:00:33 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12255


Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com


--- Comment #1 from Steven Schveighoffer <schveiguy at yahoo.com> 2014-02-25 14:00:30 PST ---
First, AAs should use equals instead of compare. At the moment, it uses
compare(a, b) == 0, which should be equivalent to equals. Also note that some
structs may be able to compare via equality, but not ordered.

Second, I believe only struct keys which satisfy one of the following two
conditions should be allowed:

1. Neither opCmp nor opEquals are defined.

Rationale: If neither opCmp nor opEquals are defined, then equals(a, b) is
guaranteed to be equivalent to compare(a, b) == 0, since the compiler generated
the functions. Note that this applies recursively in the case of member structs
if the compiler is generating the function.

2. Both opEquals and toHash are defined.

Rationale: if opEquals is specially defined, then toHash must also be specially
defined. If opEquals only examines part of the object, then toHash would have
to be modified to only examine part of the object as well.

All other structs should be disallowed as keys.

Rationale: Only opEquals will be used for comparison. If one defines opCmp but
not opEquals, then the builtin opEquals may not be equivalent to opCmp() == 0,
and the AA will not use the correct comparison tool.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list