hash 클래스

값에 대한 해시 코드를 계산합니다.

구문

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

설명

함수 개체는 Ty 형식의 값을 인덱스 값의 분포에 매핑하는 데 적합한 해시 함수를 정의합니다. 멤버 operator() 는 val에 대한 해시 코드를 반환하며, 클래스 템플릿unordered_map, unordered_multimapunordered_setunordered_multiset. 표준 라이브러리는 기본 형식에 대한 특수화를 제공합니다. Ty는 포인터 형식 및 열거형 형식을 비롯한 스칼라 형식일 수 있습니다. 도한 라이브러리 형식 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, variantvector<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

요구 사항

헤더:<기능>

네임스페이스: std

참고 항목

<unordered_map>
unordered_multimap 클래스
unordered_multiset 클래스
<unordered_set>