[ Web Proxy ]
URL:
Viewing: https://ko.cppreference.com/cpp/utility/functional/less [Back]  [Original]

std::less - cppreference.com
cppreference.com

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.

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]

Web Proxy Viewer  |  New URL  |  Original Page