命名空间
变体
操作

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) (C++26 起)
template< class Y >
bool owner_equal( const std::shared_ptr<Y>& other ) const noexcept;
(2) (C++26 起)

检查此 weak_ptrother 是否共享所有权,或是否都为空。该比较使得两个智能指针仅在它们都为空,或它们都拥有同一对象时才比较为等价,即使通过 get() 获得指针值不同(例如因为它们指向同一对象中的不同子对象)。

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

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

目录

[编辑] 参数

其他 - 要比较的 std::shared_ptrstd::weak_ptr

[编辑] 返回值

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

[编辑] 注意

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

[编辑] 示例

[编辑] 参阅

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