hash Class
Computes hash code for a value.
Syntax
template <class Ty>
struct hash {
size_t operator()(Ty val) const;
};
Remarks
The function object defines a hash function, suitable for mapping values of type Ty to a distribution of index values. The member operator()
returns a hash code for val, suitable for use with class templates unordered_map
, unordered_multimap
, unordered_set
, and unordered_multiset
. The standard library provides specializations for basic types: Ty may be any scalar type, including pointer types and enumeration types. In addition, there are specializations for the library types string
, wstring
, u16string
, u32string
, string_view
, wstring_view
, u16string_view
, u32string_view
, bitset
, error_code
, error_condition
, optional
, shared_ptr
, thread
, type_index
, unique_ptr
, variant
, and vector<bool>
.
Example
// std__functional__hash.cpp
// compile with: /EHsc
#include <functional>
#include <iostream>
#include <unordered_set>
int main()
{
std::unordered_set<int, std::hash<int> > c0;
c0.insert(3);
std::cout << *c0.find(3) << std::endl;
return (0);
}
3
Requirements
Header: <functional>
Namespace: std
See also
<unordered_map>
unordered_multimap Class
unordered_multiset Class
<unordered_set>
Feedback
https://aka.ms/ContentUserFeedback.
În curând: Pe parcursul anului 2024, vom elimina treptat Probleme legate de GitHub ca mecanism de feedback pentru conținut și îl vom înlocui cu un nou sistem de feedback. Pentru mai multe informații, consultați:Trimiteți și vizualizați feedback pentru