跳到主要内容

std::owner_less

定义于头文件 <memory>

自 C++17 起
template<>
struct owner_less<void>;

std::owner_less<>std::owner_less 的一个特例化,其参数类型被推导。

成员类型

成员类型定义
is_transparent/* 未指定 */

备注

成员类型 is_transparent 向调用者表明,该函数对象是一个透明函数对象:它接受任意类型的参数并使用完美转发,这在函数对象用于异构上下文或与右值参数一起使用时,可以避免不必要的复制和转换。特别是,像 std::set::findstd::set::lower_bound 这样的模板函数会利用其 Compare 类型上的这个成员类型。

特性测试宏
__cpp_lib_transparent_operators

成员函数


puboperator()使用基于所有者的语义比较其参数
(函数)

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)

使用基于所有者的语义比较 lhsrhs。实际上调用 lhs.owner_before(rhs)

该排序是严格弱排序关系。

只有当 lhsrhs 都为空或共享所有权时,它们才相等。

参数

lhs, rhs - 要比较的共享所有权指针

返回值

如果 lhs 根据基于所有者的排序小于 rhs,则为 true


std::owner_less

定义于头文件 <memory>

自 C++17 起
template<>
struct owner_less<void>;

std::owner_less<>std::owner_less 的一个特例化,其参数类型被推导。

成员类型

成员类型定义
is_transparent/* 未指定 */

备注

成员类型 is_transparent 向调用者表明,该函数对象是一个透明函数对象:它接受任意类型的参数并使用完美转发,这在函数对象用于异构上下文或与右值参数一起使用时,可以避免不必要的复制和转换。特别是,像 std::set::findstd::set::lower_bound 这样的模板函数会利用其 Compare 类型上的这个成员类型。

特性测试宏
__cpp_lib_transparent_operators

成员函数


puboperator()使用基于所有者的语义比较其参数
(函数)

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)

使用基于所有者的语义比较 lhsrhs。实际上调用 lhs.owner_before(rhs)

该排序是严格弱排序关系。

只有当 lhsrhs 都为空或共享所有权时,它们才相等。

参数

lhs, rhs - 要比较的共享所有权指针

返回值

如果 lhs 根据基于所有者的排序小于 rhs,则为 true