Scroll to navigation

std::owner_hash(3) C++ Standard Libary std::owner_hash(3)

NAME

std::owner_hash - std::owner_hash

Synopsis

Defined in header <memory> struct owner_hash; (since C++26)

This function object provides owner-based (as opposed to value-based) hashing of both std::weak_ptr and std::shared_ptr.


Nested types

Nested type Definition is_transparent unspecified

Member functions

operator() calculates the hash of the shared-ownership pointer
(function)

std::owner_hash::operator()

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

Equivalent to return key.owner_hash();.

Parameters

key - shared-ownership pointer to be hashed

Return value

A hash value that is identical for any std::shared_ptr or std::weak_ptr object sharing the same ownership.

Notes


Feature-test macro Value Std Feature
Enabling the use of std::shared_ptr and __cpp_lib_smart_ptr_owner_equality 202306L (C++26) std::weak_ptr as keys in unordered
associative containers

See also

owner_hash provides owner-based hashing of shared pointers (C++26) (public member function of std::shared_ptr<T>) owner_hash provides owner-based hashing of weak pointers (C++26) (public member function of std::weak_ptr<T>)

2026.11.10 http://cppreference.com