次の方法で共有


hash クラス

値のハッシュ コードを計算します。

構文

template <class Ty>
struct hash {
    size_t operator()(Ty val) const;
};

解説

この関数オブジェクトは、Ty 型の値をインデックス値の分布にマッピングするのに適したハッシュ関数を定義します。 メンバー operator() は、クラス テンプレート unordered_mapunordered_multimapunordered_set、および unordered_multiset での使用に適している val のハッシュ コードを返します。 標準ライブラリには、基本型の特殊化が用意されています。Ty は、ポインター型や列挙型など、任意のスカラー型にすることができます。 また、ライブラリ型 stringwstringu16stringu32stringstring_viewwstring_viewu16string_viewu32string_viewbitseterror_codeerror_conditionoptionalshared_ptrthreadtype_indexunique_ptrvariant、および 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>