memory_owner_hash

memory_owner_hash (std::owner_hash)

<memory> 헤더에 정의되어 있어요. std::weak_ptrstd::shared_ptr 모두에 대해 소유자 기반(값 기반이 아닌) 해시를 제공하는 함수 객체예요. C++26부터 도입됐어요.

출처: cppreference

본문

struct owner_hash;

(C++26부터)

이 함수 객체는 std::weak_ptrstd::shared_ptr 모두에 대해 소유자 기반(값 기반이 아닌) 해시를 제공해요.

중첩 타입

  • is_transparent: 미지정(unspecified). 이로 인해 혼합 타입 비교가 가능해요.

멤버 함수

  • operator(): 공유 소유권 포인터의 해시 계산 (함수)

std::owner_hash::operator()

template< class T >
std::size_t operator()( const std::shared_ptr<T>& key ) const noexcept;   // (1) since C++26

template< class T >
std::size_t operator()( const std::weak_ptr<T>& key ) const noexcept;     // (2) since C++26

소유권 기반 해시를 계산해요. std::owner_equal과 함께 쓰면 소유권 기반으로 동작하는 해시 컨테이너(예: std::unordered_set<shared_ptr<T>, owner_hash, owner_equal>)를 만들 수 있어요.

std::unordered_set<std::shared_ptr<Base>,
    std::owner_hash, std::owner_equal> s;
// 소유권 기반으로 동작

더 알아보기 (Learn more)

cppreference