std:: owner_less
|
定义于头文件
<memory>
|
||
| (1) | ||
|
template
<
class
T
>
struct owner_less ; /* 未定义 */ |
(C++11 起)
(C++17 前) |
|
|
template
<
class
T
=
void
>
struct owner_less ; /* 未定义 */ |
(C++17 起) | |
|
template
<
class
T
>
struct owner_less < std:: shared_ptr < T >> ; |
(2) | (C++11 起) |
|
template
<
class
T
>
struct owner_less < std:: weak_ptr < T >> ; |
(3) | (C++11 起) |
|
template
<>
struct owner_less < void > ; |
(4) | (C++17 起) |
此函数对象提供基于所有者(而非基于值)的混合类型排序,适用于
std::weak_ptr
和
std::shared_ptr
。排序规则是:两个智能指针仅在同时为空或共享所有权时才被视为等价,即使通过
get()
获取的原始指针值不同(例如因为它们指向同一对象内的不同子对象)。
默认情况下未为弱指针定义 operator < ,该运算符可能错误地认为指向同一对象的两个共享指针不相等(参见 std::shared_ptr::owner_before )。
特化版本
当未指定
|
(C++17 起) |
嵌套类型
|
(C++20 前) |
成员函数
|
operator()
|
使用基于所有者的语义比较其参数
(函数) |
std::owner_less:: operator()
|
仅限特化版本
(2)
的成员
|
||
|
bool
operator
(
)
(
const
std::
shared_ptr
<
T
>
&
lhs,
const std:: shared_ptr < T > & rhs ) const noexcept ; |
(C++11 起) | |
|
仅限特化版本
(3)
的成员
|
||
|
bool
operator
(
)
(
const
std::
weak_ptr
<
T
>
&
lhs,
const std:: weak_ptr < T > & rhs ) const noexcept ; |
(C++11 起) | |
|
两个模板特化的成员
|
||
|
bool
operator
(
)
(
const
std::
shared_ptr
<
T
>
&
lhs,
const std:: weak_ptr < T > & rhs ) const noexcept ; |
(C++11 起) | |
|
bool
operator
(
)
(
const
std::
weak_ptr
<
T
>
&
lhs,
const std:: shared_ptr < T > & rhs ) const noexcept ; |
(C++11 起) | |
使用基于所有者的语义比较 lhs 和 rhs 。实际上调用 lhs. owner_before ( rhs ) 。
该排序是严格弱序关系。
仅当 lhs 和 rhs 均为空或共享所有权时,它们才是等价的。
参数
| lhs, rhs | - | 要比较的共享所有权指针 |
返回值
如果根据基于所有者的排序确定 lhs 小于 rhs ,则为 true ,否则为 false 。
缺陷报告
下列行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
| 缺陷报告 | 适用标准 | 发布时行为 | 正确行为 |
|---|---|---|---|
| LWG 2873 | C++11 | operator ( ) 未被要求为 noexcept | 要求为 noexcept |
参见
|
提供基于所有者的共享指针排序
(
std::shared_ptr<T>
的公开成员函数)
|
|
|
提供基于所有者的弱指针排序
(
std::weak_ptr<T>
的公开成员函数)
|