std::weak_ptr<T>:: owner_equal
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Modifiers | ||||
| Observers | ||||
|
(C++26)
|
||||
|
weak_ptr::owner_equal
(C++26)
|
||||
| Non-member functions | ||||
| Helper classes | ||||
|
(C++20)
|
||||
| Deduction guides (C++17) |
|
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_ptr
与
other
是否共享所有权或均为空。该比较遵循以下规则:两个智能指针仅当它们均为空或拥有同一对象时才被视为等价,即使通过
get()
获取的指针值不同(例如因为它们指向同一对象内的不同子对象)。
成员函数
owner_equal
是一种等价关系,当且仅当
!
owner_before
(
other
)
&&
!
other.
owner_before
(
*
this
)
为
true
时,
owner_equal
(
other
)
才为
true
。
这种排序方式使得共享指针和弱指针能够作为无序关联容器的键值使用,通常通过 std::owner_equal 实现。
目录 |
参数
| 其他 | - | 待比较的 std::shared_ptr 或 std::weak_ptr |
返回值
若 * this 与 other 共享所有权或均为空,则返回 true ;否则返回 false 。
注释
| 功能测试 宏 | 值 | 标准 | 功能 |
|---|---|---|---|
__cpp_lib_smart_ptr_owner_equality
|
202306L
|
(C++26) |
允许在
无序关联容器
中使用
std::weak_ptr
作为键值
|
示例
|
本节内容不完整
原因:示例 |
参见
|
(C++26)
|
提供共享指针和弱指针的混合类型基于所有者的相等比较
(类) |