[unord.hash]

# 22 General utilities library [[utilities]](./#utilities)

## 22.10 Function objects [[function.objects]](function.objects#unord.hash)

### 22.10.19 Class template hash [unord.hash]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15566)

The unordered associative containers defined in [[unord]](unord "23.5 Unordered associative containers") use
specializations of the class template hash ([[functional.syn]](functional.syn "22.10.2 Header <functional> synopsis"))
as the default hash function[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15573)

Each specialization of hash is either enabled or disabled,
as described below[.](#2.sentence-1)

[*Note [1](#note-1)*:

Enabled specializations meet the [*Cpp17Hash*](hash.requirements#:Cpp17Hash "16.4.4.5 Cpp17Hash requirements [hash.requirements]") requirements, and
disabled specializations do not[.](#2.sentence-2)

â *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[.](#2.sentence-3)

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[.](#2.sentence-4)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15587)

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[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15592)

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>, andis_move_assignable_v<H>[.](#4.sentence-1)

Disabled specializations of hash are not function object types ([[function.objects]](function.objects "22.10 Function objects"))[.](#4.sentence-2)

[*Note [2](#note-2)*:

This means that the specialization of hash exists, but
any attempts to use it as a [*Cpp17Hash*](hash.requirements#:Cpp17Hash "16.4.4.5 Cpp17Hash requirements [hash.requirements]") will be ill-formed[.](#4.sentence-3)

â *end note*]

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15607)

An enabled specialization hash<Key> will:

- [(5.1)](#5.1)

meet the [*Cpp17Hash*](hash.requirements#:Cpp17Hash "16.4.4.5 Cpp17Hash requirements [hash.requirements]") requirements (Table [37](hash.requirements#tab:cpp17.hash "Table 37: Cpp17Hash requirements")),
with Key as the function
call argument type, the [*Cpp17DefaultConstructible*](utility.arg.requirements#:Cpp17DefaultConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [30](utility.arg.requirements#tab:cpp17.defaultconstructible "Table 30: Cpp17DefaultConstructible requirements")),
the [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")),
the [*Cpp17Swappable*](swappable.requirements#:Cpp17Swappable "16.4.4.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")),

- [(5.2)](#5.2)

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;

- [(5.3)](#5.3)

meet the requirement that the expression h(k), where h is an object of type hash<Key> and k is an object of typeKey, shall not throw an exception unless hash<Key> is a
program-defined specialization[.](#5.sentence-1)
