How to specialize std::hash::operator() for user-defined type in unordered containers?

You are expressly allowed and encouraged to add specializations to namespace std*. The correct (and basically only) way to add a hash function is this: namespace std { template <> struct hash<Foo> { size_t operator()(const Foo & x) const { /* your code here, e.g. “return hash<int>()(x.value);” */ } }; } (Other popular specializations that … Read more