std::less

Header: <functional>

Function object for performing comparisons. The main template invokes operator< on type T.

# Declarations

template< class T >
struct less;

(until C++14)

template< class T = void >
struct less;

(since C++14)

# Parameters

# Return value

lhs < rhs.

# Example

#include <functional>
 
template<typename A, typename B, typename C = std::less<>>
constexpr bool fun(A a, B b, C cmp = C{})
{
    return cmp(a, b);
}
 
static_assert(fun(1, 2) == true);
static_assert(fun(1.0, 1) == false);
static_assert(fun(1, 2.0) == true);
static_assert(std::less<int>{}(5, 5.6) == false);   // 5 < 5 (warn: implicit conversion)
static_assert(std::less<double>{}(5, 5.6) == true); // 5.0 < 5.6
static_assert(std::less<int>{}(5.6, 5.7) == false); // 5 < 5 (warn: implicit conversion)
static_assert(std::less{}(5, 5.6) == true);         // less<void>: 5.0 < 5.6
 
int main() {}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2562C++98the pointer total order might be inconsistentguaranteed to be consistent

# See also