Is there any reason why we don't have something like this in
Phobos?
hash_t toHash(T)(in T t) if (isIntegral!(T) || isSomeChar!(T))
{
return t;
}
hash_t toHash(T)(in T[] t)
{
typeof(return) h = 0;
foreach (item; t)
{ h = h * 37 + item.toHash(); }
return h;
}
hash_t toHash(T)(in T t) if (!isIntegral!(T) && !isSomeChar!(T)
&& !isArray!(T))
{
typeof(return) h = 0;
foreach (ref a; t.tupleof)
{ h = h * 37 + a.toHash(); }
return h;
}
hash_t toHash(T...)(in Tuple!(T) t)
{
typeof(return) h = 0;
foreach (item; t)
{ h = h * 37 + item.toHash(); }
return h;
}