std::shared_ptr<T>:: owner_equal
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Modifiers | ||||
| Observers | ||||
|
(C++17)
|
||||
|
(
until C++20*
)
|
||||
|
(C++26)
|
||||
|
shared_ptr::owner_equal
(C++26)
|
||||
| Non-member functions | ||||
|
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(C++20)
|
||||
|
functions
(
until C++26*
)
|
||||
| Helper classes | ||||
|
(C++20)
|
||||
| Deduction guides (C++17) |
|
template
<
class
Y
>
bool owner_equal ( const std:: shared_ptr < Y > & other ) const noexcept ; |
(1) | (自 C++26 起) |
|
template
<
class
Y
>
bool owner_equal ( const std:: weak_ptr < Y > & other ) const noexcept ; |
(2) | (自 C++26 起) |
检查此
shared_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::shared_ptr
用作
无序关联容器
的键值
|
示例
|
本节内容不完整
原因:示例 |
参见
|
(C++26)
|
提供共享指针与弱指针的混合类型基于所有者的相等比较
(类) |