命名空间
变体
操作

std::weak_ptr<T>::owner_hash

来自 cppreference.cn
< cpp‎ | memory‎ | weak_ptr
 
 
内存管理库
(仅作说明*)
未初始化内存算法
(C++17)
(C++17)
(C++17)
受约束的未初始化
内存算法
C 库

分配器
内存资源
垃圾回收支持
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
未初始化存储
(直到 C++20*)
(直到 C++20*)
显式生命周期管理
 
 
std::size_t owner_hash() const noexcept;
(C++26 起)

返回一个未指定的值,使得对于任何对象 other,如果 owner_equal(other)true,则 owner_hash() == other.owner_hash() 也为 true

此哈希用于使共享指针和弱指针可用作无序关联容器中的键,通常通过 std::owner_hash

目录

[编辑] 返回值

对于共享相同所有权的任何 std::shared_ptrstd::weak_ptr 对象,返回值是相同的。

[编辑] 注意

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

[编辑] 示例

[编辑] 参阅

为共享指针和弱指针提供基于所有者的哈希
(类) [编辑]