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.
Requirements
The type T satisfies Hash if
- The type
Tsatisfies FunctionObject, CopyConstructible, Destructible, and
Given
-
h, a value of typeTorconst T, whose argument type isKey, -
k, a value of type convertible toKeyorconst Key, -
u, an lvalue expression of typeKey.
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 The probability of |
h(u)
|
std::size_t | u is not modified.
|
Standard library
| (C++11) |
hash function object (class template) |
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 |
Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.