Unordered associative containers (C++): Difference between revisions

Content deleted Content added
m typo
Borneq (talk | contribs)
Custom hash functions: make sample working
Line 202:
To use custom objects in std::unordered_map, a custom hash function must be defined. This function takes a const reference to the custom type and returns a size_t
<source lang="cpp">
#include <unordered_map>
struct X{int i,j,k;};
 
struct hash_X{
size_t operator()(const X &x) const{
return std::hash<int>()(x.i) ^ std::hash<int>()(x.j) ^ std::hash<int>()(x.k);
}
};