std::less
Min standard notice:
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
lhs, rhs: values to compare
# 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
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2562 | C++98 | the pointer total order might be inconsistent | guaranteed to be consistent |