首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::owner_less

Defined in header <memory>

(1)

template< class T > struct owner_less; /* undefined */

(since C++11) (until C++17)

template< class T = void > struct owner_less; /* undefined */

(since C++17)

template< class T > struct owner_less<std::shared_ptr<T>>;

(2)

(since C++11)

template< class T > struct owner_less<std::weak_ptr<T>>;

(3)

(since C++11)

template<> struct owner_less<void>;

(4)

(since C++17)

此函数对象提供基于所有者的%28 AS,而不是两者的基于值的%29混合类型排序。std::weak_ptrstd::shared_ptr.顺序是这样的,只有当两个智能指针都是空的,或者它们都管理同一个对象时,它们才能比较等价的值,即使get()是不同的。因为它们指向同一对象%29内的不同子对象。

类模板是构建关联容器时的首选比较谓词。std::shared_ptrstd::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<不是为弱指针定义的,并且可能错误地考虑了同一个对象的两个共享指针---非等效的%28(请参见shared_ptr::owner_before29%。

专门性

The standard library provides a specialization of std::owner_less when T is not specified. In this case, the parameter types are deduced from the arguments (each of which must still be either a std::shared_ptr or a std::weak_ptr). owner_less<void> function object providing mixed-type owner-based ordering of shared and weak pointers, regardless of the type of the pointee (class template specialization)

owner_less<void>

function object providing mixed-type owner-based ordering of shared and weak pointers, regardless of the type of the pointee (class template specialization)

(since C++17)

owner_less<void>

function object providing mixed-type owner-based ordering of shared and weak pointers, regardless of the type of the pointee (class template specialization)

成员类型

Member type

Definition

result_type(deprecated in c++17)

2-3) bool

first_argument_type(deprecated in c++17)

2) std::shared_ptr<T>3) std::weak_ptr<T>

second_argument_type(deprecated in c++17)

2) std::shared_ptr<T>3) std::weak_ptr<T>

成员函数

operator()

compares its arguments using owner-based semantics (function)

STD:业主[医]减::操作员%28%29

bool operator()( const std::shared_ptr<T>& lhs, const std::shared_ptr<T>& rhs ) const;

(since C++11) (member only of owner_less<shared_ptr<T>> template specialization)

bool operator()( const std::shared_ptr<T>& lhs, const std::weak_ptr<T>& rhs ) const;

(since C++11)

bool operator()( const std::weak_ptr<T>& lhs, const std::shared_ptr<T>& rhs ) const;

(since C++11)

bool operator()( const std::weak_ptr<T>& lhs, const std::weak_ptr<T>& rhs ) const;

(since C++11) (member only of owner_less<weak_ptr<T>> template specialization)

比较lhsrhs使用基于所有者的语义。有效呼叫lhs.owner_before(rhs)...

排序是严格弱序关系。

lhsrhs只有当它们都是空的或共享的所有权时,它们才是等价的。

参数

lhs, rhs

-

shared-ownership pointers to compare

返回值

true如果lhs少于rhs由业主依据订单确定。

例外

(none)

(until C++17)

noexcept specification: noexcept

(since C++17)

另见

owner_before

provides owner-based ordering of shared pointers (public member function of std::shared_ptr)

owner_before

provides owner-based ordering of weak pointers (public member function of std::weak_ptr)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券