C++ named requirements: Hash (since C++11)
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
C++ named requirements
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Hash
(C++11)
(C++17)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++17)
(C++20)
(C++20)
(C++20)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++14)
(C++14)
(C++11)
(C++11)
(C++17)
(C++14)
(C++20)
(C++20)
(C++23)
(C++23)
(C++23)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
A Hash is a function object for which the output depends only on the input and has a very low probability of yielding the same output given different input values.
[edit] Requirements
The type T satisfies Hash if
- The type
Tsatisfies FunctionObject, CopyConstructible, Destructible, and
Given
- h, a value of type
Torconst T, whose argument type isKey, - k, a value of type convertible to
Keyor const Key, - u, an lvalue expression of type
Key.
The following expressions must be valid and have their specified effects.
| Expression | Return type | Requirements |
|---|---|---|
| h(k) | std::size_t | The returned value depends only on the value of k for the duration of the program.
All evaluations of h(k) executed within a given execution of a program yield the same result for the same value of k. The probability of h(a) == h(b) for a != b should approach 1.0 / std::numeric_limits <std::size_t >::max(). |
| h(u) | std::size_t | u is not modified. |
[edit] Standard library
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2291 | C++11 | same results for same arguments were required in all cases | only required within a single execution |