compare_common_comparison_category
compare_common_comparison_category (공통 비교 범주)
이 페이지는 C++20에서 도입된 std::common_comparison_category 클래스 템플릿에 대해 설명해요. 이 템플릿은 주어진 타입들 모두가 변환될 수 있는 가장 강한 비교 범주 타입을 제공해요. 즉, 여러 비교 범주 타입 중 공통으로 사용할 수 있는 최상위 범주를 알아내는 데 사용해요.
출처: cppreference
본문
헤더 <compare>에 정의됨 |
||
|---|---|---|
template < class ... Ts > struct common_comparison_category { using type = /* see below */ ; }; |
(since C++20) |
클래스 템플릿 std::common_comparison_category는 템플릿 인자 Ts... 모두가 변환될 수 있는 가장 강한 비교 범주에 대한 별칭(멤버 typedef type)을 제공해요.
자세히 설명하면, n개의 타입 T0 ... Tn-1 목록의 공통 비교 타입은 다음과 같이 정의돼요.
- 어떤
Ti가 비교 범주 타입(std::partial_ordering,std::weak_ordering,std::strong_ordering)이 아니라면,U는void예요. - 그렇지 않고, 최소한 하나의
Ti가std::partial_ordering이라면,U는std::partial_ordering이에요. - 그렇지 않고, 최소한 하나의
Ti가std::weak_ordering이라면,U는std::weak_ordering이에요. - 그렇지 않다면 (모든
Ti가std::strong_ordering이거나 목록이 비어 있다면),U는std::strong_ordering이에요.
템플릿 매개변수
| ...Ts | - | 비어 있을 수 있는 타입 목록 |
헬퍼 템플릿
| template < class ... Ts > using common_comparison_category_t = common_comparison_category < Ts ... >:: type ; | | (since 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 ; }; } // namespace 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 ) ) > {};
예제
이 섹션은 불완전해요. 이유: 예제가 없어요.
같이 보기
strong_ordering (C++20) |
모든 6개 연산자를 지원하고 대체 가능한(substitutable) 3방향 비교의 결과 타입 (클래스) |
|---|---|
weak_ordering (C++20) |
모든 6개 연산자를 지원하지만 대체 가능하지 않은 3방향 비교의 결과 타입 (클래스) |
partial_ordering (C++20) |
모든 6개 연산자를 지원하고, 대체 가능하지 않으며, 비교 불가능한 값을 허용하는 3방향 비교의 결과 타입 (클래스) |