20 General utilities library [utilities]

20.14 Function objects [function.objects]

20.14.18 Class template hash [unord.hash]

The unordered associative containers defined in [unord] use specializations of the class template hash ([functional.syn]) as the default hash function.
Each specialization of hash is either enabled or disabled, as described below.
[Note
:
Enabled specializations meet the Cpp17Hash requirements, and disabled specializations do not.
— end note
]
Each header that declares the template hash provides enabled specializations of hash for nullptr_­t and all cv-unqualified arithmetic, enumeration, and pointer types.
For any type Key for which neither the library nor the user provides an explicit or partial specialization of the class template hash, hash<Key> is disabled.
If the library provides an explicit or partial specialization of hash<Key>, that specialization is enabled except as noted otherwise, and its member functions are noexcept except as noted otherwise.
If H is a disabled specialization of hash, these values are false: is_­default_­constructible_­v<H>, is_­copy_­constructible_­v<H>, is_­move_­constructible_­v<H>, is_­copy_­assignable_­v<H>, and is_­move_­assignable_­v<H>.
Disabled specializations of hash are not function object types.
[Note
:
This means that the specialization of hash exists, but any attempts to use it as a Cpp17Hash will be ill-formed.
— end note
]
An enabled specialization hash<Key> will:
  • meet the Cpp17Hash requirements (Table 34), with Key as the function call argument type, the Cpp17DefaultConstructible requirements (Table 27), the Cpp17CopyAssignable requirements (Table 31),
  • be swappable ([swappable.requirements]) for lvalues,
  • meet the requirement that if k1 == k2 is true, h(k1) == h(k2) is also true, where h is an object of type hash<Key> and k1 and k2 are objects of type Key;
  • meet the requirement that the expression h(k), where h is an object of type hash<Key> and k is an object of type Key, shall not throw an exception unless hash<Key> is a program-defined specialization that depends on at least one program-defined type.