値のハッシュ コードを計算します。
template<class Ty>
struct hash
: public unary_function<Ty, size_t> {
size_t operator()(Ty _Val) const;
};
解説
このメンバー関数は、ハッシュ関数を定義します。型 Ty の値をインデックス値の分布にマッピングするのに適しています。このメンバー演算子は、_Val のハッシュ コードを返します。unordered_map、unordered_multimap、unordered_set、および unordered_multiset の各テンプレート クラスでの使用に適しています。Ty には、string、wstring、error_code、error_condition、u16string、または u32string の任意のスカラー型を指定できます。
使用例
// std_tr1__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);
}
必要条件
ヘッダー : <functional>
名前空間: std