Weird error when compiling.

TheFlyingFiddle theflyingfiddle at gmail.com
Sat Oct 19 19:14:53 PDT 2013


> Anyway to evaluate the name of the class and return its hash at 
> compile time?

I couldn't find the built in hash unction for strings so i used 
the one from http://dlang.org/hash-map.html as an example. More 
advanced and better hash functions can be found online.

public class ComponentDetail(T) : Component {
	////////////////////////////////////////////////////////////
	/// Component's ID as static member.
	public static hash_t ID = hash!(T);
}

hash_t hash(T)()
{
     hash_t hash;
     foreach (char c; T.stringof)
         hash = (hash * 9) + c;
     return hash;
}


More information about the Digitalmars-d-learn mailing list