File indexing completed on 2026-05-03 08:13:25
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___COMPARE_ORDERING_H
0010 #define _LIBCPP___CXX03___COMPARE_ORDERING_H
0011
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__type_traits/enable_if.h>
0014 #include <__cxx03/__type_traits/is_same.h>
0015
0016 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0017 # pragma GCC system_header
0018 #endif
0019
0020 _LIBCPP_BEGIN_NAMESPACE_STD
0021
0022 #if _LIBCPP_STD_VER >= 20
0023
0024
0025 enum class _OrdResult : signed char { __less = -1, __equiv = 0, __greater = 1 };
0026
0027 enum class _NCmpResult : signed char { __unordered = -127 };
0028
0029 class partial_ordering;
0030 class weak_ordering;
0031 class strong_ordering;
0032
0033 template <class _Tp, class... _Args>
0034 inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...);
0035
0036 struct _CmpUnspecifiedParam {
0037 _LIBCPP_HIDE_FROM_ABI constexpr _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
0038
0039 template <class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
0040 _CmpUnspecifiedParam(_Tp) = delete;
0041 };
0042
0043 class partial_ordering {
0044 using _ValueT = signed char;
0045
0046 _LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
0047
0048 _LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_NCmpResult __v) noexcept : __value_(_ValueT(__v)) {}
0049
0050 _LIBCPP_HIDE_FROM_ABI constexpr bool __is_ordered() const noexcept {
0051 return __value_ != _ValueT(_NCmpResult::__unordered);
0052 }
0053
0054 public:
0055
0056 static const partial_ordering less;
0057 static const partial_ordering equivalent;
0058 static const partial_ordering greater;
0059 static const partial_ordering unordered;
0060
0061
0062 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
0063
0064 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
0065 return __v.__is_ordered() && __v.__value_ == 0;
0066 }
0067
0068 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
0069 return __v.__is_ordered() && __v.__value_ < 0;
0070 }
0071
0072 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
0073 return __v.__is_ordered() && __v.__value_ <= 0;
0074 }
0075
0076 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
0077 return __v.__is_ordered() && __v.__value_ > 0;
0078 }
0079
0080 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
0081 return __v.__is_ordered() && __v.__value_ >= 0;
0082 }
0083
0084 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
0085 return __v.__is_ordered() && 0 < __v.__value_;
0086 }
0087
0088 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
0089 return __v.__is_ordered() && 0 <= __v.__value_;
0090 }
0091
0092 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
0093 return __v.__is_ordered() && 0 > __v.__value_;
0094 }
0095
0096 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
0097 return __v.__is_ordered() && 0 >= __v.__value_;
0098 }
0099
0100 _LIBCPP_HIDE_FROM_ABI friend constexpr partial_ordering
0101 operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
0102 return __v;
0103 }
0104
0105 _LIBCPP_HIDE_FROM_ABI friend constexpr partial_ordering
0106 operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
0107 return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v);
0108 }
0109
0110 private:
0111 _ValueT __value_;
0112 };
0113
0114 inline constexpr partial_ordering partial_ordering::less(_OrdResult::__less);
0115 inline constexpr partial_ordering partial_ordering::equivalent(_OrdResult::__equiv);
0116 inline constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater);
0117 inline constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered);
0118
0119 class weak_ordering {
0120 using _ValueT = signed char;
0121
0122 _LIBCPP_HIDE_FROM_ABI explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
0123
0124 public:
0125 static const weak_ordering less;
0126 static const weak_ordering equivalent;
0127 static const weak_ordering greater;
0128
0129 _LIBCPP_HIDE_FROM_ABI constexpr operator partial_ordering() const noexcept {
0130 return __value_ == 0 ? partial_ordering::equivalent
0131 : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
0132 }
0133
0134
0135 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
0136
0137 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
0138 return __v.__value_ == 0;
0139 }
0140
0141 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
0142 return __v.__value_ < 0;
0143 }
0144
0145 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
0146 return __v.__value_ <= 0;
0147 }
0148
0149 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
0150 return __v.__value_ > 0;
0151 }
0152
0153 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
0154 return __v.__value_ >= 0;
0155 }
0156
0157 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
0158 return 0 < __v.__value_;
0159 }
0160
0161 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
0162 return 0 <= __v.__value_;
0163 }
0164
0165 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
0166 return 0 > __v.__value_;
0167 }
0168
0169 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
0170 return 0 >= __v.__value_;
0171 }
0172
0173 _LIBCPP_HIDE_FROM_ABI friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
0174 return __v;
0175 }
0176
0177 _LIBCPP_HIDE_FROM_ABI friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
0178 return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v);
0179 }
0180
0181 private:
0182 _ValueT __value_;
0183 };
0184
0185 inline constexpr weak_ordering weak_ordering::less(_OrdResult::__less);
0186 inline constexpr weak_ordering weak_ordering::equivalent(_OrdResult::__equiv);
0187 inline constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater);
0188
0189 class strong_ordering {
0190 using _ValueT = signed char;
0191
0192 _LIBCPP_HIDE_FROM_ABI explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
0193
0194 public:
0195 static const strong_ordering less;
0196 static const strong_ordering equal;
0197 static const strong_ordering equivalent;
0198 static const strong_ordering greater;
0199
0200
0201 _LIBCPP_HIDE_FROM_ABI constexpr operator partial_ordering() const noexcept {
0202 return __value_ == 0 ? partial_ordering::equivalent
0203 : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
0204 }
0205
0206 _LIBCPP_HIDE_FROM_ABI constexpr operator weak_ordering() const noexcept {
0207 return __value_ == 0 ? weak_ordering::equivalent : (__value_ < 0 ? weak_ordering::less : weak_ordering::greater);
0208 }
0209
0210
0211 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
0212
0213 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
0214 return __v.__value_ == 0;
0215 }
0216
0217 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
0218 return __v.__value_ < 0;
0219 }
0220
0221 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
0222 return __v.__value_ <= 0;
0223 }
0224
0225 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
0226 return __v.__value_ > 0;
0227 }
0228
0229 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
0230 return __v.__value_ >= 0;
0231 }
0232
0233 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
0234 return 0 < __v.__value_;
0235 }
0236
0237 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
0238 return 0 <= __v.__value_;
0239 }
0240
0241 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
0242 return 0 > __v.__value_;
0243 }
0244
0245 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
0246 return 0 >= __v.__value_;
0247 }
0248
0249 _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering
0250 operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
0251 return __v;
0252 }
0253
0254 _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering
0255 operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
0256 return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v);
0257 }
0258
0259 private:
0260 _ValueT __value_;
0261 };
0262
0263 inline constexpr strong_ordering strong_ordering::less(_OrdResult::__less);
0264 inline constexpr strong_ordering strong_ordering::equal(_OrdResult::__equiv);
0265 inline constexpr strong_ordering strong_ordering::equivalent(_OrdResult::__equiv);
0266 inline constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater);
0267
0268
0269
0270
0271 template <class _Tp>
0272 concept __comparison_category = __one_of_v<_Tp, partial_ordering, weak_ordering, strong_ordering>;
0273
0274 #endif
0275
0276 _LIBCPP_END_NAMESPACE_STD
0277
0278 #endif