std::owner_less
定义于头文件 <memory>
。
template<>
struct owner_less<void>;
std::owner_less<>
是 std::owner_less 的一个特例化,其参数类型被推导。
成员类型
成员类型 | 定义 |
---|---|
is_transparent | /* 未指定 */ |
备注
成员类型 is_transparent 向调用者表明,该函数对象是一个透明函数对象:它接受任意类型的参数并使用完美转发,这在函数对象用于异构上下文或与右值参数一起使用时,可以避免不必要的复制和转换。特别是,像 std::set::find
和 std::set::lower_bound
这样的模板函数会利用其 Compare 类型上的这个成员类型。
特性测试宏 |
---|
__cpp_lib_transparent_operators |
成员函数
pub | operator() | 使用基于所有者的语义比较其参数 (函数) |
std::owner_less<void>::operator()
template<class T, class U>
bool operator()( const std::shared_ptr<T>& lhs,
const std::shared_ptr<U>& rhs ) const noexcept; // (since C++11)
template<class T, class U>
bool operator()( const std::shared_ptr<T>& lhs,
const std::weak_ptr<U>& rhs ) const noexcept; // (since C++11)
template<class T, class U>
bool operator()( const std::weak_ptr<T>& lhs,
const std::shared_ptr<U>& rhs ) const noexcept; // (since C++11)
template<class T, class U>
bool operator()( const std::weak_ptr<T>& lhs,
const std::weak_ptr<U>& rhs ) const noexcept; // (since C++11)
使用基于所有者的语义比较 lhs
和 rhs
。实际上调用 lhs.owner_before(rhs)
。
该排序是严格弱排序关系。
只有当 lhs
和 rhs
都为空或共享所有权时,它们才相等。
参数
lhs
, rhs
- 要比较的共享所有权指针
返回值
如果 lhs
根据基于所有者的排序小于 rhs
,则为 true
。