Namespaces
Variants

std::common_comparison_category

ja.cppreference.net より
 
 
ユーティリティライブラリ
言語サポート
型サポート (基本型、RTTI)
ライブラリ機能テストマクロ (C++20)
プログラムユーティリティ
可変長引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (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 のすべてを変換可能な最も強い比較カテゴリのエイリアス(メンバ型 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; };
} // 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)