On 28.08.2010 16:37, Kevin Bailey wrote:
So I have a class containing two strings:
class Foo
{
string s1, s2;
...
and I'd like to add a toHash() member, but I can't find
the built-in string hash function. These don't work:
s1.toHash()
s1.toHash
s1.hash
s1.hash()
hash(s1)
yet strings can clearly be the key in a map.
I see that xml.d writes its own string hash function
but that just doesn't seem right.
Is there a way to get to the built-in ?
You can get to it through TypeInfo:
http://www.digitalmars.com/d/2.0/phobos/object.html#getHash
string a = "abc";
auto hash = typeid(a).getHash(&a);