Namespaces
Variants

std:: owner_hash

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
定义于头文件 <memory>
struct owner_hash ;
(C++26 起)

此函数对象提供基于所有者(而非基于值)的 std::weak_ptr std::shared_ptr 哈希计算。

目录

嵌套类型

嵌套类型 定义
is_transparent 未指定

成员函数

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)

等价于 return key. owner_hash ( ) ;

参数

key - 待哈希的共享所有权指针

返回值

对于共享相同所有权的任意 std::shared_ptr std::weak_ptr 对象均相同的哈希值。

注释

功能测试 标准 功能
__cpp_lib_smart_ptr_owner_equality 202306L (C++26) 允许将 std::shared_ptr std::weak_ptr 用作 无序关联容器 的键值

参见

(C++26)
提供基于所有者的共享指针哈希计算
( std::shared_ptr<T> 的公开成员函数)
(C++26)
提供基于所有者的弱指针哈希计算
( std::weak_ptr<T> 的公开成员函数)