std::common_comparison_category
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   在标头  <compare> 定义
  | 
||
|   template<class... Ts> struct common_comparison_category {  | 
(C++20 起) | |
类模板 std::common_comparison_category 为所有模板实参 Ts... 所能转换到的最强比较类别提供别名(作为成员 typedef 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) )> {};  | 
示例
| 本节未完成 原因:暂无示例  | 
参阅
|    (C++20)  | 
  三路比较的结果类型,支持所有 6 种运算符且可替换  (类)  | 
|    (C++20)  | 
  三路比较的结果类型,支持所有 6 种运算符且不可替换  (类)  | 
|    (C++20)  | 
  三路比较的结果类型,支持所有 6 种运算符,不可替换,并允许不可比较的值  (类)  |