On 08/28/2010 10:25 PM, bearophile wrote:
torhu:
string a = "abc";
auto hash = typeid(a).getHash(&a);
If higher performance is necessary, you may pre-compute part of that:
void main() {
string a = "abc";
auto hash1 = typeid(a).getHash(&a);
auto stringHash =&(typeid(a).getHash);
auto hash2 = stringHash(&a);
assert(hash1 == hash2);
}
Bye,
bearophile
I doubt that gives any performance gains. typeid(a).getHash should be a
constant expression anyway, and I don't see any gains in my tiny
benchmark test.
Perhaps it works better if a was an Object, since typeid for objects
does more.