Getting the hash of any value easily?

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 10:38:02 PDT 2014


On Wed, Jul 30, 2014 at 06:07:57PM -0700, Andrei Alexandrescu via Digitalmars-d wrote:
> A coworker asked about the idiomatic way to get the hash of a string
> in D, and somewhat surprisingly the best answer I could find is: "to
> get the hash of an lvalue x, call typeof(x).getHash(&x)."
> 
> That's admittedly quite clunky and indirect. Is it worth it to
> simplify that by means of a template in object.di?
[...]

It's about time somebody noticed this!!

Why don't we just expose druntime's core.internal.hash.hashOf() function
somewhere? It's not as though it isn't already in druntime, so the
function is already present in the executable, we just need a public
declaration of it somewhere that users can make use of.

Not to mention, it's already a template function that correctly
calculates the hash of various built-in types.


T

-- 
The problem with the world is that everybody else is stupid.


More information about the Digitalmars-d mailing list