计算值的哈希代码。
语法
template <class Ty>
struct hash {
    size_t operator()(Ty val) const;
};
备注
此成员对象定义一个哈希函数,适合将 Ty 类型的值映射到索引值的分布。 成员 operator() 会返回 val 的一个哈希代码,适合用于类模板 unordered_map、unordered_multimap、unordered_set 和 unordered_multiset。 此标准库对基本类型提供专用化:Ty 可能为任何标量类型,包括指针类型和枚举类型。 此外,还具有库类型 string、wstring、u16string、u32string、string_view、wstring_view、u16string_view、u32string_view、bitset、error_code、error_condition、optional、shared_ptr、threadtype_index、unique_ptr、variant 和 vector<bool> 的专用化。
示例
// 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
要求
标头:<functional>
命名空间: std
另请参阅
<unordered_map>
unordered_multimap 类
unordered_multiset 类
<unordered_set>