共用方式為


hash 類別

計算值的雜湊碼。

語法

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

備註

函式物件會定義雜湊函式,適用於將 Ty 類型的值對應到索引值的分佈。 成員 operator() 會傳回 val 雜湊碼,適合用於類別範本 unordered_mapunordered_multimapunordered_setunordered_multiset 。 標準程式庫提供適用於基本類型的特製化:Ty 可以是任何純量類型,包括指標類型和列舉類型。 此外,還有適用於程式庫類型 stringwstringu16stringu32stringstring_viewwstring_viewu16string_viewu32string_viewbitseterror_codeerror_conditionoptionalshared_ptrthreadtype_indexunique_ptrvariantvector<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

需求

Header: < functional>

命名空間:std

另請參閱

<unordered_map>
unordered_multimap 類別
unordered_multiset 類別
<unordered_set>