std::weak_ptr<T>::owner_equal
来自 cppreference.cn
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_ptr
与 other
是否共享所有权或均为空。此比较使得仅当两个智能指针均为空,或均拥有同一对象时,它们才比较等价,即使由 `get()` 取得的指针值不同(例如,因为它们指向同一对象内的不同子对象)。
成员函数 `owner_equal` 是一个等价关系,使得当且仅当 `owner_equal(other)` 为 `true` 时,`!owner_before(other) && !other.owner_before(*this)` 才为 `true`。
此排序被用于使共享指针和弱指针可用作无序关联式容器中的键,通常通过 `std::owner_equal`。
目录 |
[编辑] 参数
other | - | 要比较的 std::shared_ptr 或 std::weak_ptr |
[编辑] 返回值
如果 *this 与 other 共享所有权或均为空,则为 true。否则,返回 false。
[编辑] 注解
特性测试 宏 | 值 | 标准 | 特性 |
---|---|---|---|
__cpp_lib_smart_ptr_owner_equality |
202306L |
(C++26) | 启用在无序关联式容器中使用 std::weak_ptr 作为键 |
[编辑] 示例
本节尚不完整 原因:示例 |
[编辑] 参见
(C++26) |
提供共享指针和弱指针的基于所有者的混合类型相等比较 (类) |