Array toHash()

David Held via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Nov 26 16:25:10 PST 2014


I have a class which contains an int[] and some other stuff.  I want to 
use my class as the key for an AA, so I am overriding toHash().  But the 
int[] is the only part which should produce the hash code.  I know that 
int[].toHash() is defined somehow, because I can put int[] directly into 
an AA without writing any hash functions.  But I don't know how to spell 
this explicitly or force the compiler to generate it for me so that I 
can forward to it in my toHash().  For illustration:

class Foo
{
     override
     size_t toHash() @trusted pure const nothrow
     {
         // error: no property 'toHash' for type 'int[]'
         return importantStuff.toHash();
     }

     // override opEquals() too...

     int[] importantStuff;
     bool  notImportant;
     int   ignoreMe;
}

Any way to avoid re-implementing this hash function?

Dave


More information about the Digitalmars-d-learn mailing list