std::owner_hash
来自 cppreference.cn
定义于头文件 <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) | (自 C++26 起) |
template< class T > std::size_t operator()( const std::weak_ptr<T>& key ) const noexcept; |
(2) | (自 C++26 起) |
等价于 return key.owner_hash();。
参数
key | - | 要哈希的共享所有权指针 |
返回值
对于任何共享相同所有权的 std::shared_ptr 或 std::weak_ptr 对象,哈希值都相同。
[编辑] 注解
特性测试 宏 | 值 | Std | 特性 |
---|---|---|---|
__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> 的公共成员函数) |