Override std::hash<std::string> to use Google's City Hash

577 Views Asked by At

So, simple enough question as I'm having a brain dead moment.. How can I override/replace std::hash<std::string> to use Google's City Hash?

My current approach is to have a wrapper around std::string and then specialize std::hash<> for that. But this is painful as I have to implement virtually the same interface as std::string and I want to avoid this.

1

There are 1 best solutions below

0
On BEST ANSWER

You can't replace any existing specializations, i.e., you can't replace std::hash<std::string>. However, you can use a different hash function objects with the std::unordered_* containers, e.g.:

std::unordered_map<std::string, T, my_hash> hash_map;