AA with complex keytype?
Stewart Gordon
smjg_1998 at yahoo.com
Fri Feb 9 08:54:48 PST 2007
Manfred Nowak Wrote:
<snip>
> Why are classes required to implement opCmp( Object) for AA's to
> function properly?
Apparently because Walter doesn't like the idea of providing an alternative implementation of AAs for unordered classes, but hasn't to my knowledge given a truly convincing reason.
My library implementation
http://pr.stewartsplace.org.uk/d/sutil/
uses only toHash and opEquals, thus works on unordered types.
> Currently AA's misbehave if opCmp(Object) is not overwritten for a
> class, but no error is thrown.
Currently? Not under DMD 1.005 as I try it. Please supply a code example that demonstrates this behaviour.
> For the transitivity of an ordering it suffices for opCmp(Object)
> to always give "==" if the objects are equal, and give "<" if they
> are not.
So if x != y, then both x < y and y < x? That wouldn't make sense at all.
> It should be easy to implement this as the default opCmp(Object).
OUAT, Object.opCmp was set up to compare the memory addresses, but this behaviour was removed to prepare for copying/compacting GC, and probably partly to eliminate the confusing behaviour it created.
Stewart.
More information about the Digitalmars-d
mailing list