Standard library header <compare> (C++20)
From cppreference.net
이 헤더는 언어 지원 라이브러리의 일부입니다.
개념(Concepts) |
||
|
주어진 타입들에 대해
<=>
연산자가 일관된 결과를 생성함을 명시
(concept) |
||
클래스 |
||
|
(C++20)
|
6개의 연산자를 모두 지원하고, 치환 가능하지 않으며, 비교 불가능한 값을 허용하는 3-way 비교의 결과 타입
(class) |
|
|
(C++20)
|
6개의 연산자를 모두 지원하고 대체 가능하지 않은 3-way 비교의 결과 타입
(클래스) |
|
|
(C++20)
|
6개의 연산자를 모두 지원하고 대체 가능한 3-way 비교의 결과 타입
(클래스) |
|
|
(C++20)
|
주어진 모든 타입이 변환될 수 있는 가장 강력한 비교 범주
(클래스 템플릿) |
|
|
(C++20)
|
주어진 타입들에 대한 삼중 비교 연산자
<=>
의 결과 타입을 구함
(클래스 템플릿) |
|
|
(C++20)
|
x
<=>
y
를 구현하는 제약된 함수 객체
(클래스) |
|
커스터마이제이션 포인트 객체 |
||
|
(C++20)
|
3-way 비교를 수행하고
std::strong_ordering
타입의 결과를 생성함
(커스터마이제이션 포인트 객체) |
|
|
(C++20)
|
3-way 비교를 수행하고
std::weak_ordering
타입의 결과를 생성함
(커스터마이제이션 포인트 객체) |
|
|
(C++20)
|
3방향 비교를 수행하고
std::partial_ordering
타입의 결과를 생성합니다
(커스터마이제이션 포인트 객체) |
|
|
(C++20)
|
3방향 비교를 수행하고
std::strong_ordering
타입의 결과를 생성하며,
operator
<=>
를 사용할 수 없는 경우에도 작동합니다
(커스터마이제이션 포인트 객체) |
|
|
(C++20)
|
3방향 비교를 수행하고
std::weak_ordering
타입의 결과를 생성합니다.
operator
<=>
를 사용할 수 없는 경우에도 동작합니다
(커스터마이제이션 포인트 객체) |
|
|
(C++20)
|
3방향 비교를 수행하고
std::partial_ordering
타입의 결과를 생성합니다.
operator
<=>
가 사용 불가능한 경우에도 동작합니다
(커스터마이제이션 포인트 객체) |
|
함수 |
||
|
명명된 비교 함수
(함수) |
||
시놉시스
namespace std { // 비교 범주 타입 class partial_ordering; class weak_ordering; class strong_ordering; // 명명된 비교 함수 constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; } constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; } constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; } constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; } constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; } constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; } // 공통 비교 범주 타입 template<class... Ts> struct common_comparison_category { using type = /* see description */; }; template<class... Ts> using common_comparison_category_t = typename common_comparison_category<Ts...>::type; // concept three_way_comparable template<class T, class Cat = partial_ordering> concept three_way_comparable = /* see description */; template<class T, class U, class Cat = partial_ordering> concept three_way_comparable_with = /* see description */; // 삼중 비교 결과 template<class T, class U = T> struct compare_three_way_result; template<class T, class U = T> using compare_three_way_result_t = typename compare_three_way_result<T, U>::type; // class compare_three_way struct compare_three_way; // 비교 알고리즘 inline namespace /* unspecified */ { inline constexpr /* unspecified */ strong_order = /* unspecified */; inline constexpr /* unspecified */ weak_order = /* unspecified */; inline constexpr /* unspecified */ partial_order = /* unspecified */; inline constexpr /* unspecified */ compare_strong_order_fallback = /* unspecified */; inline constexpr /* unspecified */ compare_weak_order_fallback = /* unspecified */; inline constexpr /* unspecified */ compare_partial_order_fallback = /* unspecified */; } }
개념
three_way_comparable
namespace std { template<class T, class Cat> concept __ComparesAs = // 설명 전용 same_as<common_comparison_category_t<T, Cat>, Cat>; template<class T, class U> concept __PartiallyOrderedWith = // 설명 전용 requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t < u } -> boolean-testable; { t > u } -> boolean-testable; { t <= u } -> boolean-testable; { t >= u } -> boolean-testable; { u < t } -> boolean-testable; { u > t } -> boolean-testable; { u <= t } -> boolean-testable; { u >= t } -> boolean-testable; }; template<class T, class Cat = partial_ordering> concept three_way_comparable = __WeaklyEqualityComparableWith<T, T> && __PartiallyOrderedWith<T, T> && requires(const remove_reference_t<T>& a, const remove_reference_t<T>& b) { { a <=> b } -> __ComparesAs<Cat>; }; }
개념
three_way_comparable_with
namespace std { template<class T, class U, class Cat = partial_ordering> concept three_way_comparable_with = __WeaklyEqualityComparableWith<T, U> && __PartiallyOrderedWith<T, U> && three_way_comparable<T, Cat> && three_way_comparable<U, Cat> && common_reference_with<const remove_reference_t<T>&, const remove_reference_t<U>&> && three_way_comparable< common_reference_t< const remove_reference_t<T>&, const remove_reference_t<U>&>, Cat> && requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t <=> u } -> __ComparesAs<Cat>; { u <=> t } -> __ComparesAs<Cat>; }; }
클래스 std:: partial_ordering
namespace std { class partial_ordering { int value; // 설명용 전용 bool is_ordered; // 설명용 전용 // 설명용 전용 생성자들 constexpr explicit partial_ordering(eq v) noexcept : value(int(v)), is_ordered(true) {} // 설명용 전용 constexpr explicit partial_ordering(ord v) noexcept : value(int(v)), is_ordered(true) {} // 설명용 전용 constexpr explicit partial_ordering(ncmp v) noexcept : value(int(v)), is_ordered(false) {} // 설명용 전용 public: // 유효한 값들 static const partial_ordering less; static const partial_ordering equivalent; static const partial_ordering greater; static const partial_ordering unordered; // 비교 연산들 friend constexpr bool operator==(partial_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default; friend constexpr bool operator< (partial_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr bool operator> (partial_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr bool operator<=(partial_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr bool operator>=(partial_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr bool operator< (/* 지정되지 않음 */, partial_ordering v) noexcept; friend constexpr bool operator> (/* 지정되지 않음 */, partial_ordering v) noexcept; friend constexpr bool operator<=(/* 지정되지 않음 */, partial_ordering v) noexcept; friend constexpr bool operator>=(/* 지정되지 않음 */, partial_ordering v) noexcept; friend constexpr partial_ordering operator<=>(partial_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr partial_ordering operator<=>(/* 지정되지 않음 */, partial_ordering v) noexcept; }; // 유효한 값들의 정의 inline constexpr partial_ordering partial_ordering::less(ord::less); inline constexpr partial_ordering partial_ordering::equivalent(eq::equivalent); inline constexpr partial_ordering partial_ordering::greater(ord::greater); inline constexpr partial_ordering partial_ordering::unordered(ncmp::unordered); }
클래스 std:: weak_ordering
namespace std { class weak_ordering { int value; // 설명 전용 // 설명 전용 생성자들 constexpr explicit weak_ordering(eq v) noexcept : value(int(v)) {} // 설명 전용 constexpr explicit weak_ordering(ord v) noexcept : value(int(v)) {} // 설명 전용 public: // 유효한 값들 static const weak_ordering less; static const weak_ordering equivalent; static const weak_ordering greater; // 변환 constexpr operator partial_ordering() const noexcept; // 비교 연산 friend constexpr bool operator==(weak_ordering v, /* unspecified */) noexcept; friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default; friend constexpr bool operator< (weak_ordering v, /* unspecified */) noexcept; friend constexpr bool operator> (weak_ordering v, /* unspecified */) noexcept; friend constexpr bool operator<=(weak_ordering v, /* unspecified */) noexcept; friend constexpr bool operator>=(weak_ordering v, /* unspecified */) noexcept; friend constexpr bool operator< (/* unspecified */, weak_ordering v) noexcept; friend constexpr bool operator> (/* unspecified */, weak_ordering v) noexcept; friend constexpr bool operator<=(/* unspecified */, weak_ordering v) noexcept; friend constexpr bool operator>=(/* unspecified */, weak_ordering v) noexcept; friend constexpr weak_ordering operator<=>(weak_ordering v, /* unspecified */) noexcept; friend constexpr weak_ordering operator<=>(/* unspecified */, weak_ordering v) noexcept; }; // 유효한 값들의 정의 inline constexpr weak_ordering weak_ordering::less(ord::less); inline constexpr weak_ordering weak_ordering::equivalent(eq::equivalent); inline constexpr weak_ordering weak_ordering::greater(ord::greater); }
클래스 std:: strong_ordering
namespace std { class strong_ordering { int value; // 설명용 전용 // 설명용 전용 생성자들 constexpr explicit strong_ordering(eq v) noexcept : value(int(v)) {} // 설명용 전용 constexpr explicit strong_ordering(ord v) noexcept : value(int(v)) {} // 설명용 전용 public: // 유효한 값들 static const strong_ordering less; static const strong_ordering equal; static const strong_ordering equivalent; static const strong_ordering greater; // 변환 constexpr operator partial_ordering() const noexcept; constexpr operator weak_ordering() const noexcept; // 비교 연산 friend constexpr bool operator==(strong_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default; friend constexpr bool operator< (strong_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr bool operator> (strong_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr bool operator<=(strong_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr bool operator>=(strong_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr bool operator< (/* 지정되지 않음 */, strong_ordering v) noexcept; friend constexpr bool operator> (/* 지정되지 않음 */, strong_ordering v) noexcept; friend constexpr bool operator<=(/* 지정되지 않음 */, strong_ordering v) noexcept; friend constexpr bool operator>=(/* 지정되지 않음 */, strong_ordering v) noexcept; friend constexpr strong_ordering operator<=>(strong_ordering v, /* 지정되지 않음 */) noexcept; friend constexpr strong_ordering operator<=>(/* 지정되지 않음 */, strong_ordering v) noexcept; }; // 유효한 값들의 정의 inline constexpr strong_ordering strong_ordering::less(ord::less); inline constexpr strong_ordering strong_ordering::equal(eq::equal); inline constexpr strong_ordering strong_ordering::equivalent(eq::equivalent); inline constexpr strong_ordering strong_ordering::greater(ord::greater); }
클래스 std:: compare_three_way
namespace std { struct compare_three_way { template<class T, class U> constexpr auto operator()(T&& t, U&& u) const; using is_transparent = /* 지정되지 않음 */; }; }
참고 항목
3-way 비교 연산자
표현식
lhs
<=>
rhs
(C++20)
|