indirect_hash

indirect_hash (std::hashstd::indirect)

<memory> 헤더에 정의되어 있어요. std::indirect에 대한 std::hash의 부분 특수화로, indirect 객체가 소유한 객체의 해시를 얻을 수 있게 해줘요. C++26부터 도입됐어요.

출처: cppreference

본문

template< class T, class Allocator >
struct hash<std::indirect<T, Allocator>>;

(C++26부터)

std::indirect에 대한 std::hash의 부분 특수화는 사용자가 indirect 객체가 소유한 객체의 해시를 얻을 수 있게 해줘요.

std::hash<std::indirect<T, Allocator>> 특수화는 std::hash<T>가 활성화되어 있으면 활성화되고, 그렇지 않으면 비활성화돼요.

활성화되었을 때, std::indirect<T, Allocator> 타입의 객체 obj에 대해 std::hash<std::indirect<T, Allocator>>()(obj)는 다음과 같이 평가돼요.

  • obj가 valueless가 아니면 std::hash<T>()(*obj).
  • obj가 valueless이면 구현 정의 값.

이 특수화의 멤버 함수는 T의 해시가 던질 수 있으므로 noexcept가 보장되지 않아요.

std::indirect<int> a = 42;
std::size_t h = std::hash<std::indirect<int>>{}(a);  // *a 의 해시와 동일

더 알아보기 (Learn more)

cppreference