std::common_comparison_category
来自 cppreference.cn
定义于头文件 <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个操作符,不可替换,并允许不可比较值的三路比较的结果类型 (类) |