std::common_comparison_category
來自 cppreference.com
定義於標頭檔案 <compare> |
||
template< class... Ts > struct common_comparison_category |
(C++20 起) | |
類模板 std::common_comparison_category
提供了一個別名(作為成員 typedef type
),用於表示所有模板引數 Ts...
都可以轉換成的最強比較類別。
具體來說,型別列表 T0...Tn-1 的公共比較型別定義如下:
- 如果任何 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 = 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) )> {}; |
[編輯] 示例
本節不完整 原因:無示例 |
[編輯] 另請參閱
(C++20) |
支援所有6個運算子並且可替換的三路比較的結果型別 (類) |
(C++20) |
支援所有6個運算子但不可替換的三路比較的結果型別 (類) |
(C++20) |
支援所有6個運算子,不可替換,並允許不可比較值的三路比較的結果型別 (類) |