定义于头文件
<memory>
|
||
(1) | ||
template< class T >
struct owner_less; /* undefined */ |
(C++11 起) (C++17 前) |
|
template< class T = void >
struct owner_less; /* undefined */ |
(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()
获得的裸指针值相异(例如,因为它们指向同一对象中的不同子对象)
在以 std::shared_ptr 或 std::weak_ptr 为关键建立关联容器,即
std::map<std::shared_ptr<T>, U, std::owner_less<std::shared_ptr<T>>>
或
std::map<std::weak_ptr<T>, U, std::owner_less<std::weak_ptr<T>>> 时,此类模板受到偏好。
默认的 operator< 不为弱指针定义,并且可能错误地认为同一对象的二个共享指针不等价(见 shared_ptr::owner_before )。
目录 |
标准库提供
|
(C++17 起) |
成员类型 | 定义 |
result_type (C++17 中弃用)
|
2-3) bool |
first_argument_type (C++17 中弃用)
|
2) std::shared_ptr<T> 3) std::weak_ptr<T> |
second_argument_type (C++17 中弃用)
|
2) std::shared_ptr<T> 3) std::weak_ptr<T> |
operator()
|
用基于占有者的语义比较其参数 (函数) |
bool operator()( const std::shared_ptr<T>& lhs,
const std::shared_ptr<T>& rhs ) const; |
(C++11 起) (仅为 owner_less<shared_ptr<T>> 模板特化的成员) |
|
bool operator()( const std::shared_ptr<T>& lhs,
const std::weak_ptr<T>& rhs ) const; |
(C++11 起) | |
bool operator()( const std::weak_ptr<T>& lhs,
const std::shared_ptr<T>& rhs ) const; |
(C++11 起) | |
bool operator()( const std::weak_ptr<T>& lhs,
const std::weak_ptr<T>& rhs ) const; |
(C++11 起) (仅为 owner_less<weak_ptr<T>> 模板特化的成员) |
|
用基于拥有者的语义比较 lhs
与 rhs
。等效于调用 lhs.owner_before(rhs) 。
顺序是严格弱序关系。
lhs
与 rhs
相等,当且仅当它们均为空或共享所有权。
lhs, rhs | - | 要比较的共享所有权指针 |
若按照基于拥有者的顺序所确定, lhs
小于 rhs
则为 true 。
(无) | (C++17 前) |
noexcept 规定:
noexcept
|
(C++17 起) |
提供基于拥有者的共享指针排序 ( std::shared_ptr 的公开成员函数)
|
|
提供弱指针的基于拥有者顺序 ( std::weak_ptr 的公开成员函数)
|