命名空间
变体
操作

std::shared_ptr<T>::owner_equal

来自 cppreference.cn
< cpp‎ | memory‎ | shared 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::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_ptrother 是否共享所有权或均为空。此比较使得仅当两个智能指针都为空或者它们都拥有同一对象时才等价,即使通过 get() 获得的指针值不同(例如,因为它们指向同一对象内的不同子对象)。

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

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

目录

[编辑] 参数

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

[编辑] 返回值

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

[编辑] 注解

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

[编辑] 示例

[编辑] 参见

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