CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sat, 19 Jul 2025 15:32:25 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/functional/hash/
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 19 Jul 2025 15:32:25 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"917e-ng+RTHhvGrmAvOeNsBlvnmi9JCQ"
Content-Encoding: gzip
Unary function object class that defines the default hash function used by the standard library.
The functional call returns a hash value of its argument: A hash value is a value that depends solely on its argument, returning always the same value for the same argument (for a given execution of a program). The value returned shall have a small likelihood of being the same as the one returned for a different argument (with chances of collision approaching
Other function object types can be used as Hash for unordered containers provided they behave as defined above and they are at least copy-constructible, destructible function objects.
The default hash is a template class that is not defined for the general case. But all library implementations provide at least the following type-specific specializations:
Apart from being callable with an argument of the appropriate types, all objects of hash instantiations are default-constructible, copy-constructible, copy-assignable, destructible and swappable.
Users can provide custom specializations for this template with these same properties.
Output:
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
<functional>
functions
wrapper classes
- binary_negate
-
functionC++11
-
reference_wrapperC++11
- unary_negate
operator classes
other classes
-
bad_function_callC++11
-
hashC++11
-
is_bind_expressionC++11
-
is_placeholderC++11
-
namespaces
-
placeholdersC++11
-
deprecated
- Reference
- <functional>
- hash
class template
<functional>
std::hash
template <class T> struct hash;
Default hash function object class
The functional call returns a hash value of its argument: A hash value is a value that depends solely on its argument, returning always the same value for the same argument (for a given execution of a program). The value returned shall have a small likelihood of being the same as the one returned for a different argument (with chances of collision approaching
1/numeric_limits<size_t>::max
).Other function object types can be used as Hash for unordered containers provided they behave as defined above and they are at least copy-constructible, destructible function objects.
The default hash is a template class that is not defined for the general case. But all library implementations provide at least the following type-specific specializations:
header | types |
---|---|
<functional> | bool |
char | |
signed char | |
unsigned char | |
char16_t | |
char32_t | |
wchar_t | |
short | |
unsigned short | |
int | |
unsigned int | |
long | |
unsigned long | |
long long | |
unsigned long long | |
float | |
double | |
long double | |
T* (for any type T) | |
<string> | string |
wstring | |
u16string | |
u32string | |
<memory> | unique_ptr |
shared_ptr | |
<vector> | vector<bool> |
<bitset> | bitset |
<system_error> | error_code |
<typeindex> | type_index |
<thread> | thread::id |
Apart from being callable with an argument of the appropriate types, all objects of hash instantiations are default-constructible, copy-constructible, copy-assignable, destructible and swappable.
Users can provide custom specializations for this template with these same properties.
Member types
member type | definition | notes |
---|---|---|
result_type | size_t | The type of the hash values produced. |
argument_type | T | The type of the values taken as argument. |
Member functions
Example
|
|
Output:
same hashes: nts1 and nts2: false str1 and str2: true |
Exception safety
No-throw guarantee: no members throw exceptions (this applies to the specializations provided in the library implementation). Custom specializations may provide different guarantees.
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us