名稱空間
變體
操作

std::common_comparison_category

來自 cppreference.com
< cpp‎ | 工具
 
 
 
定義於標頭檔案 <compare>
template< class... Ts >

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

};
(C++20 起)

類模板 std::common_comparison_category 提供了一個別名(作為成員 typedef type),用於表示所有模板引數 Ts... 都可以轉換成的最強比較類別。

具體來說,型別列表 T0...Tn-1 的公共比較型別定義如下:

目錄

[編輯] 模板引數

...Ts - 可能為空的型別列表

[編輯] 輔助模板

template< class... Ts >
using common_comparison_category_t = common_comparison_category<Ts...>::type;
(C++20 起)

[編輯] 成員型別

成員型別 定義
型別 最強的公共比較類別(如上定義)

[編輯] 可能實現

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個運算子並且可替換的三路比較的結果型別
(類) [編輯]
支援所有6個運算子但不可替換的三路比較的結果型別
(類) [編輯]
支援所有6個運算子,不可替換,並允許不可比較值的三路比較的結果型別
(類) [編輯]