Namespaces
Variants

std::common_comparison_category

cppreference.net에서 가져옴
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐기됨)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
교체 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
헤더 <compare>
template< class... Ts >
struct common_comparison_category
{
    using type = /* see below */ ;
};
에 정의됨 (C++20부터)

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

자세히는, n개의 타입 목록 T0...Tn-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)