functional_less_equal

functional_less_equal (x <= y 비교 함수 객체)

std::less_equal은 C++ 표준 라이브러리에서 제공하는 비교 함수 객체예요. 이 함수 객체는 두 값을 비교하여 첫 번째 값이 두 번째 값보다 작거나 같은지(lhs <= rhs)를 확인하는 데 사용돼요. 주로 정렬 알고리즘, 연관 컨테이너, 그리고 다양한 표준 라이브러리 구성 요소에서 비교 기준으로 활용할 수 있어요.

출처: cppreference

본문

정의와 개요

<functional> 헤더에 정의되어 있어요. 기본 템플릿은 T 타입에 대해 operator<=를 호출해요.

Defined in header <functional>
template< class T > struct less_equal; (until C++14)
template< class T = void > struct less_equal; (since C++14)

특수화

less_equal<void> (C++14) x <= y를 구현하고 매개변수와 반환 타입을 추론하는 함수 객체 (클래스 템플릿 특수화)

멤버 타입

Type Definition
result_type (C++17에서 deprecated, C++20에서 제거) bool
first_argument_type (C++17에서 deprecated, C++20에서 제거) T
second_argument_type (C++17에서 deprecated, C++20에서 제거) T
이 멤버 타입들은 std::binary_function<T, T, bool>을 public 상속하여 얻어요. (until C++11)

멤버 함수

operator() 첫 번째 인자가 두 번째 인자보다 작거나 같은지 확인해요 (public 멤버 함수)

std::less_equal::operator()

bool operator()( const T& lhs, const T& rhs ) const;

lhsrhs보다 작거나 같은지 확인해요.

매개변수

lhs, rhs - 비교할 값들

반환값

lhs <= rhs를 반환해요.

T가 포인터 타입인 경우, 결과는 구현에서 정의하는 포인터에 대한 엄격한 전체 순서(strict total order)와 일관돼요.

예외

구현에서 정의하는 예외를 던질 수 있어요.

가능한 구현

constexpr bool operator()( const T& lhs, const T& rhs ) const
{
    return lhs <= rhs; // assumes that the implementation handles pointer total order
}

결함 보고서

다음 동작 변경 결함 보고서는 이전에 발표된 C++ 표준에 소급 적용되었어요.

DR Applied to Behavior as published Correct behavior
LWG 2562 C++98 the pointer total order might be inconsistent guaranteed to be consistent

더 알아보기

less x < y를 구현하는 함수 객체 (클래스 템플릿)
ranges::less_equal (C++20) x <= y를 구현하는 제약된 함수 객체 (클래스)

더 알아보기 (Learn more)

cppreference