File indexing completed on 2026-05-03 08:13:16
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___COMPARE_COMMON_COMPARISON_CATEGORY_H
0010 #define _LIBCPP___COMPARE_COMMON_COMPARISON_CATEGORY_H
0011
0012 #include <__compare/ordering.h>
0013 #include <__config>
0014 #include <__cstddef/size_t.h>
0015 #include <__type_traits/is_same.h>
0016
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 # pragma GCC system_header
0019 #endif
0020
0021 _LIBCPP_BEGIN_NAMESPACE_STD
0022
0023 #if _LIBCPP_STD_VER >= 20
0024
0025 namespace __comp_detail {
0026
0027 enum _ClassifyCompCategory : unsigned { _None, _PartialOrd, _WeakOrd, _StrongOrd, _CCC_Size };
0028
0029 template <class _Tp>
0030 _LIBCPP_HIDE_FROM_ABI constexpr _ClassifyCompCategory __type_to_enum() noexcept {
0031 if (is_same_v<_Tp, partial_ordering>)
0032 return _PartialOrd;
0033 if (is_same_v<_Tp, weak_ordering>)
0034 return _WeakOrd;
0035 if (is_same_v<_Tp, strong_ordering>)
0036 return _StrongOrd;
0037 return _None;
0038 }
0039
0040 template <size_t _Size>
0041 _LIBCPP_HIDE_FROM_ABI constexpr _ClassifyCompCategory
0042 __compute_comp_type(const _ClassifyCompCategory (&__types)[_Size]) {
0043 int __seen[_CCC_Size] = {};
0044 for (auto __type : __types)
0045 ++__seen[__type];
0046 if (__seen[_None])
0047 return _None;
0048 if (__seen[_PartialOrd])
0049 return _PartialOrd;
0050 if (__seen[_WeakOrd])
0051 return _WeakOrd;
0052 return _StrongOrd;
0053 }
0054
0055 template <class... _Ts, bool _False = false>
0056 _LIBCPP_HIDE_FROM_ABI constexpr auto __get_comp_type() {
0057 using _CCC = _ClassifyCompCategory;
0058 constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...};
0059 constexpr _CCC __cat = __comp_detail::__compute_comp_type(__type_kinds);
0060 if constexpr (__cat == _None)
0061 return void();
0062 else if constexpr (__cat == _PartialOrd)
0063 return partial_ordering::equivalent;
0064 else if constexpr (__cat == _WeakOrd)
0065 return weak_ordering::equivalent;
0066 else if constexpr (__cat == _StrongOrd)
0067 return strong_ordering::equivalent;
0068 else
0069 static_assert(_False, "unhandled case");
0070 }
0071 }
0072
0073
0074 template <class... _Ts>
0075 struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
0076 using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
0077 };
0078
0079 template <class... _Ts>
0080 using common_comparison_category_t = typename common_comparison_category<_Ts...>::type;
0081
0082 #endif
0083
0084 _LIBCPP_END_NAMESPACE_STD
0085
0086 #endif