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... が変換可能な最も強い比較カテゴリに対するエイリアス(メンバ型 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; };
} // 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)
    )> {};

関連項目

すべての6つの演算子をサポートし、置換可能な3方向比較の結果型
(class)
すべての6つの演算子をサポートし、置換不可能な3方向比較の結果型
(class)
すべての6つの演算子をサポートし、置換不可能で、比較不能な値を許容する3方向比較の結果型
(class)