std::less
Defined in header <functional> | | |
|---|---|---|
template< class T > struct less; | | (until C++14) |
template< class T = void > struct less; | | (since C++14) |
用于执行比较的函数对象。除非专门化,否则调用operator<论类型T...
专门性
...的专业化std::less对于任何指针类型,都会产生严格的总顺序,即使内置operator<不会的。严格的全序在专业之间是一致的。std::less,,,std::greater,,,std::less_equal,和std::greater_equal对于该指针类型,并且与相应的内建运算符%28施加的偏序一致。<,,,>,,,<=和>=29%。
If the function call operator of the specialization std::less<void> calls a built-in operator comparing pointers, it yields a strict total order even if the built-in operator< does not.This strict total order is consistent among the specializations std::less<void>, std::greater<void>, std::less_equal<void>, and std::greater_equal<void>, and is also consistent with the partial order imposed by the corresponding built-in operators. | (since C++14) |
|---|
The standard library provides a specialization of std::less when T is not specified, which leaves the parameter types and return type to be deduced. less<void> function object implementing x < y deducing argument and return types (class template specialization) | less<void> | function object implementing x < y deducing argument and return types (class template specialization) | (since C++14) |
|---|---|---|---|
less<void> | function object implementing x < y deducing argument and return types (class template specialization) |
成员类型
type | definition |
|---|---|
result_type(deprecated in C++17) | bool |
first_argument_type(deprecated in C++17) | T |
second_argument_type(deprecated in C++17) | T |
成员函数
operator() | checks if the first argument is less than the second (public member function) |
|---|
STD::较少::操作员%28%29
bool operator()( const T& lhs, const T& rhs ) const; | | (until C++14) |
|---|---|---|
constexpr bool operator()( const T& lhs, const T& rhs ) const; | | (since C++14) |
检查是否lhs是再少点比rhs...
参数
lhs, rhs | - | values to compare |
|---|
返回值
true如果lhs < rhs,,,false否则。
例外
%280%29
可能的实施
ConstT&rhs,constT&rhs%29 const{返回lhs<rhs;}
*。
例
二次
#include <functional>
#include <iostream>
template <typename A, typename B, typename U = std::less<int>>
bool f(A a, B b, U u = U())
{
return u(a, b);
}
int main()
{
std::cout << std::boolalpha;
std::cout << f(5, 20) << '\n';
std::cout << f(100, 10) << '\n';
}二次
产出:
二次
true
false二次
另见
owner_less (C++11) | provides mixed-type owner-based ordering of shared and weak pointers (class template) |
|---|---|
greater | function object implementing x > y (class template) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

