Namespaces
Variants

std:: common_comparison_category

From cppreference.net
Utilities library
헤더에 정의됨 <compare>
template < class ... Ts >

struct common_comparison_category
{
using type = /* 아래 참조 */ ;

} ;
(C++20부터)

클래스 템플릿 std::common_comparison_category 는 모든 템플릿 인자 Ts... 가 변환될 수 있는 가장 강력한 비교 범주에 대한 별칭(멤버 typedef type 으로)을 제공합니다.

자세히 설명하면, n개의 타입 목록 T 0 ... T n-1 의 공통 비교 타입은 다음과 같이 정의됩니다:

목차

템플릿 매개변수

...Ts - 가능한 빈 타입 목록

헬퍼 템플릿

template < class ... Ts >
using common_comparison_category_t = common_comparison_category < Ts... > :: type ;
(C++20 이후)

멤버 타입

멤버 타입 정의
type 가장 강력한 공통 비교 범주 (위에서 정의된 대로)

가능한 구현

namespace detail
{
    template<unsigned int>
    struct common_cmpcat_base     { using type = void; };
    template<>
    struct common_cmpcat_base<0u> { using type = std::strong_ordering; };
    template<>
    struct common_cmpcat_base<2u> { using type = std::partial_ordering; };
    template<>
    struct common_cmpcat_base<4u> { using type = std::weak_ordering; };
    template<>
    struct common_cmpcat_base<6u> { using type = std::partial_ordering; };
} // 네임스페이스 detail
template<class...Ts>
struct common_comparison_category :
    detail::common_cmpcat_base<(0u | ... |
        (std::is_same_v<Ts, std::strong_ordering>  ? 0u :
         std::is_same_v<Ts, std::weak_ordering>    ? 4u :
         std::is_same_v<Ts, std::partial_ordering> ? 2u : 1u)
    )> {};

예제

참고 항목

6개의 연산자를 모두 지원하고 대체 가능한 3-way 비교의 결과 타입
(class)
6개의 연산자를 모두 지원하지만 대체 불가능한 3-way 비교의 결과 타입
(class)
6개의 연산자를 모두 지원하고, 대체 불가능하며, 비교 불가능한 값을 허용하는 3-way 비교의 결과 타입
(class)