associativeArray.toHash()

Michiel nomail at please.com
Thu Feb 22 03:20:00 PST 2007


Jarrett Billingsley wrote:

>> I think I found a way in Phobos, but it might not be the most elegant
>> one. I used std.boxer to pack each element of the array into a box. Then
>> I call the Box.toHash() function on each and use the sum to calculate
>> the sets hash.
>>
>> Is there a better way?
> 
> You can use the .getHash method of the typeinfo any type, and it'll use the 
> built in hashing function.
> 
> class Set(T)
> {
>     ...
>     T[] values; // or however you store them
> 
>     void someFunc(T data)
>     {
>         hash_t hash = typeid(T).getHash(&data);
>     }
> } 

That also works nicely! I tried something similar, just not exactly like
that. Anyway, it's more elegant than my box way.

Thanks!

-- 
Michiel



More information about the Digitalmars-d mailing list