Unexpected behaviour in associative array

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Apr 19 21:27:50 UTC 2019


On Fri, Apr 19, 2019 at 08:15:22PM +0000, Arredondo via Digitalmars-d-learn wrote:
> On Friday, 19 April 2019 at 12:48:32 UTC, Adam D. Ruppe wrote:
> > It might just be that toHash is secretly dependent on various
> > attributes in the signature.
> > 
> 
> You nailed it. This was it. It was not trivial to add the missing
> @safe and const attributes, but it worked.
[...]

For the future, also note that if you want to test opCmp it's better to
use == instead of calling opCmp directly, that way you know for sure
that the compiler picked up your definition of opCmp. (IIRC if the
signature doesn't match for whatever reason the compiler may just
silently revert to the default implementation.)

Similarly, if you want to test toHash, use typeid(obj).getHash(&obj),
rather than calling toHash directly.  That way you know for sure that
the compiler has picked up your custom toHash, rather than just the
default implementation.


T

-- 
"Maybe" is a strange word.  When mom or dad says it it means "yes", but when my big brothers say it it means "no"! -- PJ jr.


More information about the Digitalmars-d-learn mailing list