year_hash

year_hash (year 해시 지원)

std::hash<std::chrono::year> 특수화가 std::chrono::year 타입에 대한 해시를 제공해요. <chrono> 헤더에 정의되어 있어요.

출처: cppreference

본문

std::chrono::yearstd::hash 특수화를 통해 해시할 수 있어요. std::hash<std::chrono::year>std::chrono::year 값을 기반으로 해시를 계산해요.

template<>
struct std::hash<std::chrono::year>;

이 특수화는 std::chrono::year를 해시 기반 컨테이너의 키로 사용할 수 있게 해줘요.

예제 (Example)

#include <chrono>
#include <iostream>
#include <unordered_set>

int main()
{
    std::unordered_set<std::chrono::year> years;
    years.insert(std::chrono::year{2020});
    std::cout << years.size() << '\n'; // 1
}

더 알아보기 (Learn more)

cppreference