std::less
cppreference.com
<tbody>
</tbody> <tbody class="t-dcl-rev ">
</tbody><tbody> </tbody>| <functional> 에 정의되어 있음.
|
||
template< class T > struct less; |
(until C++14) | |
template< class T = void > struct less; |
(since C++14) | |
비교연산을 수행하는 함수객체. 특수화하지 않았다면 T형의 operator< 연산자를 호출한다.
특수화
If the built-in operator< does not provide total order for pointers, a partial specialization of std::less for pointer types is provided, which guarantees total order.
|
|
(since C++14) |
멤버 형식
| 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 whether the first argument is less than the second (public member function) |
std::less::operator()
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody> 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) | |
Checks whether lhs is less than rhs.
Parameters
| lhs, rhs | - | values to compare |
Return value
true if lhs < rhs, false otherwise.
Exceptions
(none)
Possible implementation
constexpr bool operator()(const T &lhs, const T &rhs) const
{
return lhs < rhs;
}
|
Example
코드 실행
#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';
}
Output:
true
false
See also
function object implementing x > y (class template) |