Why D is annoying =P
Mehrdad
wfunction at hotmail.com
Wed Oct 24 13:45:35 PDT 2012
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;
}
More information about the Digitalmars-d
mailing list