![]() ![]() ![]() The standard library provides enabled specializations of std::hash for std::nullptr_t and all cv-unqualified arithmetic types (including any extended integer types), all enumeration types, and all pointer types.Įach standard library header that declares the template std::hash provides all enabled specializations described above. These may be (but are not required to be) implemented as std :: hash :: type >. In addition to the above, the standard library provides specializations for all (scoped and unscoped) enumeration types. std :: hash produces a hash of the value of the pointer (the memory address), it does not examine the contents of any character array. There is no specialization for C strings. Hash functions are only required to produce the same result for the same input within a single execution of a program this allows salted hashes that prevent collision denial-of-service attacks. In other words, these hash functions are designed to work with unordered associative containers, but not as cryptographic hashes, for example. 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"). ![]()
0 Comments
Leave a Reply. |