std::common_comparison_category
提供: cppreference.com
ヘッダ <compare> で定義
|
||
template<class... Ts> struct common_comparison_category { |
(C++20以上) | |
クラステンプレート std::common_comparison_category
はテンプレート引数 Ts...
のすべてが変換できる最も強い比較カテゴリに対するエイリアスを (メンバ型 type
として) 提供します。
詳しく言うと、 n 個の型のリスト T0...Tn-1 の共通の比較型 U は以下のように定義されます。
- いずれかの 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 = 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) )> {}; |
[編集] 例
This section is incomplete Reason: no example |
[編集] 関連項目
(C++20) |
6種類の演算子をすべてサポートする代用可能な三方比較の結果の型 (クラス) |
(C++20) |
6種類の演算子をすべてサポートする代用可能でない三方比較の結果の型 (クラス) |
(C++20) |
6種類の演算子をすべてサポートし、代用可能でなく、比較不可能な値を許容する、三方比較の結果の型 (クラス) |