In order to use your custom types with the unordered associative containers, you must perform the following steps:
- Specialize the std::hash class template for your custom type; the specialization must be done in the std namespace.
- Define synonyms for the argument and result type.
- Implement the call operator so that it takes a constant reference to your type and returns a hash value.
To compute a good hash value, you should do the following:
- Start with an initial value that should be a prime number (for example, 17).
- For each field that is used to determine whether two instances of the class are equal, adjust the hash value according to the following formula:
hashValue = hashValue * prime + hashFunc(field);
- You can use ...