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