이름공간
변수

std::less

cppreference.com
 
 
 
Function objects


Function wrappers
(C++11)
(C++11)
Bind
(C++11)
Reference wrappers
(C++11)(C++11)
Operator wrappers
Negators
Deprecated binders and adaptors
(deprecated)
(deprecated)
(deprecated)
(deprecated)
(deprecated)(deprecated)(deprecated)(deprecated)
(deprecated)
(deprecated)(deprecated)(deprecated)(deprecated)
(deprecated)(deprecated)
(deprecated)(deprecated)
 
<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.

T가 지정되지 않았을 경우 표준 라이브러리는 std::less의 특수화를 허용한다. 이를 통해 인자 형을 남길 수 있고, 반환형을 추론할 수 있다.

틀:cpp/utility/functional/dsc less void
(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) [edit]