Namespaces
Variants

std:: hash <std::experimental::optional>

From cppreference.net
헤더에 정의됨 <experimental/optional>
template < class T >
struct hash < std:: experimental :: optional < T >> ;
(라이브러리 fundamentals TS)

std::hash 의 템플릿 특수화는 std::experimental::optional 클래스에 대해 사용자가 optional 객체에 포함된 값들의 해시를 얻을 수 있도록 합니다.

템플릿 매개변수

T - optional 객체에 포함된 값의 타입. 특수화 std:: hash < T > 는 클래스 템플릿 hash 의 요구사항을 충족해야 합니다.

예제

#include <experimental/optional>
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std::literals;
int main()
{
    // hash<optional>을 사용하면 unordered_set을 사용할 수 있습니다
    std::unordered_set<std::experimental::optional<std::string>> s = {
        "abc"s, std::experimental::nullopt, "def"s
    };
    for (const auto& o : s)
        std::cout << o.value_or("(null)") << ' ';
    std::cout << '\n';
}

가능한 출력:

def abc (null)

참고 항목

(C++11)
해시 함수 객체
(클래스 템플릿)