命名空间
变体
操作

std::weak_ptr<T>::owner_equal

来自 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*)
显式生命期管理
 
 
template< class Y >
bool owner_equal( const std::weak_ptr<Y>& other ) const noexcept;
(1) (since C++26)
template< class Y >
bool owner_equal( const std::shared_ptr<Y>& other ) const noexcept;
(2) (since C++26)

检查此 weak_ptrother 是否共享所有权或均为空。此比较使得仅当两个智能指针均为空,或均拥有同一对象时,它们才比较等价,即使由 `get()` 取得的指针值不同(例如,因为它们指向同一对象内的不同子对象)。

成员函数 `owner_equal` 是一个等价关系,使得当且仅当 `owner_equal(other)` 为 `true` 时,`!owner_before(other) && !other.owner_before(*this)` 才为 `true`。

此排序被用于使共享指针和弱指针可用作无序关联式容器中的键,通常通过 `std::owner_equal`。

目录

[编辑] 参数

other - 要比较的 std::shared_ptrstd::weak_ptr

[编辑] 返回值

如果 *thisother 共享所有权或均为空,则为 true。否则,返回 false

[编辑] 注解

特性测试 标准 特性
__cpp_lib_smart_ptr_owner_equality 202306L (C++26) 启用在无序关联式容器中使用 std::weak_ptr 作为键

[编辑] 示例

[编辑] 参见

提供共享指针和弱指针的基于所有者的混合类型相等比较
(类) [编辑]