名前空間
変種
操作

std::common_comparison_category

提供: cppreference.com
< cpp‎ | utility
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
ヘッダ <compare> で定義
template<class... Ts>

struct common_comparison_category {
  using type = /*see below*/ ;

};
(C++20以上)

クラステンプレート std::common_comparison_category はテンプレート引数 Ts... のすべてが変換できる最も強い比較カテゴリに対するエイリアスを (メンバ型 type として) 提供します。

詳しく言うと、 n 個の型のリスト T0...Tn-1 の共通の比較型 U は以下のように定義されます。

目次

[編集] テンプレート引数

...Ts - 型のリスト (空でも構いません)

[編集] ヘルパーテンプレート

template< class... Ts >
using common_comparison_category_t = typename 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種類の演算子をすべてサポートする代用可能な三方比較の結果の型
(クラス) [edit]
6種類の演算子をすべてサポートする代用可能でない三方比較の結果の型
(クラス) [edit]
6種類の演算子をすべてサポートし、代用可能でなく、比較不可能な値を許容する、三方比較の結果の型
(クラス) [edit]