
Notably, some implementations use trivial (identity) hash functions which map an integer to itself. The actual hash functions are implementation-dependent and are not required to fulfill any other quality criteria except those specified above.
5 Standard specializations for library types. 4 Standard specializations for basic types. In other words, they exist, but cannot be used. std:: is_default_constructible > :: value. Disabled specializations do not satisfy Hash, do not satisfy FunctionObject, and following values are all false: The unordered associative containers std::unordered_set, std::unordered_multiset, std::unordered_map, std::unordered_multimap use specializations of the template std::hash as the default hash function.įor every type Key for which neither the library nor the user provides an enabled specialization std::hash, that specialization exists and is disabled. User-provided specializations of hash also must meet those requirements.
For two different parameters k1 and k2 that are not equal, the probability that std :: hash ( ) (k1 ) = std :: hash ( ) (k2 ) should be very small, approaching 1.0 / std:: numeric_limits :: max ( ).Īll explicit and partial specializations of hash provided by the standard library are DefaultConstructible, CopyAssignable, Swappable and Destructible. For two parameters k1 and k2 that are equal, std :: hash ( ) (k1 ) = std :: hash ( ) (k2 ). Returns a value of type std:: size_t that represents the hash value of the parameter. Accepts a single parameter of type Key. In particular, they define an operator ( ) const that: Instances of this function object satisfy Hash.
The enabled specializations of the hash template defines a function object that implements a hash function. Each specialization of this template is either enabled ("untainted") or disabled ("poisoned").