33#pragma GCC system_header
35#define __glibcxx_want_three_way_comparison
38#if __cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L
42namespace std _GLIBCXX_VISIBILITY(default)
48 using type =
signed char;
50 enum class _Ord : type { equivalent = 0, less = -1, greater = 1 };
52 enum class _Ncmp : type { _Unordered = 2 };
56 consteval __unspec(__unspec*)
noexcept { }
60 class partial_ordering
63 __cmp_cat::type _M_value;
66 partial_ordering(__cmp_cat::_Ord __v) noexcept
67 : _M_value(__cmp_cat::type(__v))
71 partial_ordering(__cmp_cat::_Ncmp __v) noexcept
72 : _M_value(__cmp_cat::type(__v))
75 friend class weak_ordering;
76 friend class strong_ordering;
80 static const partial_ordering less;
81 static const partial_ordering equivalent;
82 static const partial_ordering greater;
83 static const partial_ordering unordered;
88 operator==(partial_ordering __v, __cmp_cat::__unspec)
noexcept
89 {
return __v._M_value == 0; }
93 operator==(partial_ordering, partial_ordering)
noexcept =
default;
97 operator< (partial_ordering __v, __cmp_cat::__unspec)
noexcept
98 {
return __v._M_value == -1; }
101 friend constexpr bool
102 operator> (partial_ordering __v, __cmp_cat::__unspec)
noexcept
103 {
return __v._M_value == 1; }
106 friend constexpr bool
107 operator<=(partial_ordering __v, __cmp_cat::__unspec)
noexcept
108 {
return __v._M_value <= 0; }
111 friend constexpr bool
112 operator>=(partial_ordering __v, __cmp_cat::__unspec)
noexcept
113 {
return __cmp_cat::type(__v._M_value & 1) == __v._M_value; }
116 friend constexpr bool
117 operator< (__cmp_cat::__unspec, partial_ordering __v)
noexcept
118 {
return __v._M_value == 1; }
121 friend constexpr bool
122 operator> (__cmp_cat::__unspec, partial_ordering __v)
noexcept
123 {
return __v._M_value == -1; }
126 friend constexpr bool
127 operator<=(__cmp_cat::__unspec, partial_ordering __v)
noexcept
128 {
return __cmp_cat::type(__v._M_value & 1) == __v._M_value; }
131 friend constexpr bool
132 operator>=(__cmp_cat::__unspec, partial_ordering __v)
noexcept
133 {
return 0 >= __v._M_value; }
136 friend constexpr partial_ordering
137 operator<=>(partial_ordering __v, __cmp_cat::__unspec)
noexcept
141 friend constexpr partial_ordering
142 operator<=>(__cmp_cat::__unspec, partial_ordering __v)
noexcept
144 if (__v._M_value & 1)
145 return partial_ordering(__cmp_cat::_Ord(-__v._M_value));
152 inline constexpr partial_ordering
153 partial_ordering::less(__cmp_cat::_Ord::less);
155 inline constexpr partial_ordering
156 partial_ordering::equivalent(__cmp_cat::_Ord::equivalent);
158 inline constexpr partial_ordering
159 partial_ordering::greater(__cmp_cat::_Ord::greater);
161 inline constexpr partial_ordering
162 partial_ordering::unordered(__cmp_cat::_Ncmp::_Unordered);
166 __cmp_cat::type _M_value;
169 weak_ordering(__cmp_cat::_Ord __v) noexcept : _M_value(__cmp_cat::type(__v))
172 friend class strong_ordering;
176 static const weak_ordering less;
177 static const weak_ordering equivalent;
178 static const weak_ordering greater;
181 constexpr operator partial_ordering() const noexcept
182 {
return partial_ordering(__cmp_cat::_Ord(_M_value)); }
186 friend constexpr bool
187 operator==(weak_ordering __v, __cmp_cat::__unspec)
noexcept
188 {
return __v._M_value == 0; }
191 friend constexpr bool
192 operator==(weak_ordering, weak_ordering)
noexcept =
default;
195 friend constexpr bool
196 operator< (weak_ordering __v, __cmp_cat::__unspec)
noexcept
197 {
return __v._M_value < 0; }
200 friend constexpr bool
201 operator> (weak_ordering __v, __cmp_cat::__unspec)
noexcept
202 {
return __v._M_value > 0; }
205 friend constexpr bool
206 operator<=(weak_ordering __v, __cmp_cat::__unspec)
noexcept
207 {
return __v._M_value <= 0; }
210 friend constexpr bool
211 operator>=(weak_ordering __v, __cmp_cat::__unspec)
noexcept
212 {
return __v._M_value >= 0; }
215 friend constexpr bool
216 operator< (__cmp_cat::__unspec, weak_ordering __v)
noexcept
217 {
return 0 < __v._M_value; }
220 friend constexpr bool
221 operator> (__cmp_cat::__unspec, weak_ordering __v)
noexcept
222 {
return 0 > __v._M_value; }
225 friend constexpr bool
226 operator<=(__cmp_cat::__unspec, weak_ordering __v)
noexcept
227 {
return 0 <= __v._M_value; }
230 friend constexpr bool
231 operator>=(__cmp_cat::__unspec, weak_ordering __v)
noexcept
232 {
return 0 >= __v._M_value; }
235 friend constexpr weak_ordering
236 operator<=>(weak_ordering __v, __cmp_cat::__unspec)
noexcept
240 friend constexpr weak_ordering
241 operator<=>(__cmp_cat::__unspec, weak_ordering __v)
noexcept
242 {
return weak_ordering(__cmp_cat::_Ord(-__v._M_value)); }
246 inline constexpr weak_ordering
247 weak_ordering::less(__cmp_cat::_Ord::less);
249 inline constexpr weak_ordering
250 weak_ordering::equivalent(__cmp_cat::_Ord::equivalent);
252 inline constexpr weak_ordering
253 weak_ordering::greater(__cmp_cat::_Ord::greater);
255 class strong_ordering
257 __cmp_cat::type _M_value;
260 strong_ordering(__cmp_cat::_Ord __v) noexcept
261 : _M_value(__cmp_cat::type(__v))
266 static const strong_ordering less;
267 static const strong_ordering equal;
268 static const strong_ordering equivalent;
269 static const strong_ordering greater;
272 constexpr operator partial_ordering() const noexcept
273 {
return partial_ordering(__cmp_cat::_Ord(_M_value)); }
276 constexpr operator weak_ordering() const noexcept
277 {
return weak_ordering(__cmp_cat::_Ord(_M_value)); }
281 friend constexpr bool
282 operator==(strong_ordering __v, __cmp_cat::__unspec)
noexcept
283 {
return __v._M_value == 0; }
286 friend constexpr bool
287 operator==(strong_ordering, strong_ordering)
noexcept =
default;
290 friend constexpr bool
291 operator< (strong_ordering __v, __cmp_cat::__unspec)
noexcept
292 {
return __v._M_value < 0; }
295 friend constexpr bool
296 operator> (strong_ordering __v, __cmp_cat::__unspec)
noexcept
297 {
return __v._M_value > 0; }
300 friend constexpr bool
301 operator<=(strong_ordering __v, __cmp_cat::__unspec)
noexcept
302 {
return __v._M_value <= 0; }
305 friend constexpr bool
306 operator>=(strong_ordering __v, __cmp_cat::__unspec)
noexcept
307 {
return __v._M_value >= 0; }
310 friend constexpr bool
311 operator< (__cmp_cat::__unspec, strong_ordering __v)
noexcept
312 {
return 0 < __v._M_value; }
315 friend constexpr bool
316 operator> (__cmp_cat::__unspec, strong_ordering __v)
noexcept
317 {
return 0 > __v._M_value; }
320 friend constexpr bool
321 operator<=(__cmp_cat::__unspec, strong_ordering __v)
noexcept
322 {
return 0 <= __v._M_value; }
325 friend constexpr bool
326 operator>=(__cmp_cat::__unspec, strong_ordering __v)
noexcept
327 {
return 0 >= __v._M_value; }
330 friend constexpr strong_ordering
331 operator<=>(strong_ordering __v, __cmp_cat::__unspec)
noexcept
335 friend constexpr strong_ordering
336 operator<=>(__cmp_cat::__unspec, strong_ordering __v)
noexcept
337 {
return strong_ordering(__cmp_cat::_Ord(-__v._M_value)); }
341 inline constexpr strong_ordering
342 strong_ordering::less(__cmp_cat::_Ord::less);
344 inline constexpr strong_ordering
345 strong_ordering::equal(__cmp_cat::_Ord::equivalent);
347 inline constexpr strong_ordering
348 strong_ordering::equivalent(__cmp_cat::_Ord::equivalent);
350 inline constexpr strong_ordering
351 strong_ordering::greater(__cmp_cat::_Ord::greater);
357 is_eq(partial_ordering __cmp)
noexcept
358 {
return __cmp == 0; }
362 is_neq(partial_ordering __cmp)
noexcept
363 {
return __cmp != 0; }
367 is_lt (partial_ordering __cmp)
noexcept
368 {
return __cmp < 0; }
372 is_lteq(partial_ordering __cmp)
noexcept
373 {
return __cmp <= 0; }
377 is_gt (partial_ordering __cmp)
noexcept
378 {
return __cmp > 0; }
382 is_gteq(partial_ordering __cmp)
noexcept
383 {
return __cmp >= 0; }
387 template<
typename _Tp>
388 inline constexpr unsigned __cmp_cat_id = 1;
390 inline constexpr unsigned __cmp_cat_id<partial_ordering> = 2;
392 inline constexpr unsigned __cmp_cat_id<weak_ordering> = 4;
394 inline constexpr unsigned __cmp_cat_id<strong_ordering> = 8;
396 template<
typename... _Ts>
397 constexpr auto __common_cmp_cat()
399 constexpr unsigned __cats = (__cmp_cat_id<_Ts> | ...);
401 if constexpr (__cats & 1)
405 else if constexpr (bool(__cats & __cmp_cat_id<partial_ordering>))
406 return partial_ordering::equivalent;
409 else if constexpr (bool(__cats & __cmp_cat_id<weak_ordering>))
410 return weak_ordering::equivalent;
413 return strong_ordering::equivalent;
418 template<
typename... _Ts>
419 struct common_comparison_category
421 using type =
decltype(__detail::__common_cmp_cat<_Ts...>());
426 template<
typename _Tp>
427 struct common_comparison_category<_Tp>
428 {
using type = void; };
431 struct common_comparison_category<partial_ordering>
432 {
using type = partial_ordering; };
435 struct common_comparison_category<weak_ordering>
436 {
using type = weak_ordering; };
439 struct common_comparison_category<strong_ordering>
440 {
using type = strong_ordering; };
443 struct common_comparison_category<>
444 {
using type = strong_ordering; };
446 template<
typename... _Ts>
447 using common_comparison_category_t
448 =
typename common_comparison_category<_Ts...>::type;
450#if __cpp_lib_three_way_comparison >= 201907L
454 template<
typename _Tp,
typename _Cat>
455 concept __compares_as
456 = same_as<common_comparison_category_t<_Tp, _Cat>, _Cat>;
460 template<
typename _Tp,
typename _Cat = partial_ordering>
461 concept three_way_comparable
462 = __detail::__weakly_eq_cmp_with<_Tp, _Tp>
463 && __detail::__partially_ordered_with<_Tp, _Tp>
464 &&
requires(
const remove_reference_t<_Tp>& __a,
465 const remove_reference_t<_Tp>& __b)
467 { __a <=> __b } -> __detail::__compares_as<_Cat>;
470 template<
typename _Tp,
typename _Up,
typename _Cat = partial_ordering>
471 concept three_way_comparable_with
472 = three_way_comparable<_Tp, _Cat>
473 && three_way_comparable<_Up, _Cat>
474 && common_reference_with<const remove_reference_t<_Tp>&,
475 const remove_reference_t<_Up>&>
476 && three_way_comparable<
477 common_reference_t<const remove_reference_t<_Tp>&,
478 const remove_reference_t<_Up>&>, _Cat>
479 && __detail::__weakly_eq_cmp_with<_Tp, _Up>
480 && __detail::__partially_ordered_with<_Tp, _Up>
481 &&
requires(
const remove_reference_t<_Tp>& __t,
482 const remove_reference_t<_Up>& __u)
484 { __t <=> __u } -> __detail::__compares_as<_Cat>;
485 { __u <=> __t } -> __detail::__compares_as<_Cat>;
490 template<
typename _Tp,
typename _Up>
491 using __cmp3way_res_t
492 =
decltype(std::declval<_Tp>() <=> std::declval<_Up>());
499 template<
typename _Tp,
typename _Up>
500 struct __cmp3way_res_impl
503 template<
typename _Tp,
typename _Up>
504 requires requires {
typename __cmp3way_res_t<__cref<_Tp>, __cref<_Up>>; }
505 struct __cmp3way_res_impl<_Tp, _Up>
507 using type = __cmp3way_res_t<__cref<_Tp>, __cref<_Up>>;
512 template<
typename _Tp,
typename _Up = _Tp>
514 : __detail::__cmp3way_res_impl<_Tp, _Up>
518 template<
typename _Tp,
typename _Up = _Tp>
520 =
typename __detail::__cmp3way_res_impl<_Tp, _Up>::type;
528 template<
typename _Tp,
typename _Up>
529 concept __3way_builtin_ptr_cmp
530 =
requires(_Tp&& __t, _Up&& __u)
531 {
static_cast<_Tp&&
>(__t) <=>
static_cast<_Up&&
>(__u); }
532 && convertible_to<_Tp, const volatile void*>
533 && convertible_to<_Up, const volatile void*>
534 && !
requires(_Tp&& __t, _Up&& __u)
535 { operator<=>(
static_cast<_Tp&&
>(__t),
static_cast<_Up&&
>(__u)); }
536 && !
requires(_Tp&& __t, _Up&& __u)
537 {
static_cast<_Tp&&
>(__t).operator<=>(
static_cast<_Up&&
>(__u)); };
544 struct compare_three_way
546 template<
typename _Tp,
typename _Up>
547 requires three_way_comparable_with<_Tp, _Up>
549 operator() [[nodiscard]] (_Tp&& __t, _Up&& __u)
const
550 noexcept(
noexcept(std::declval<_Tp>() <=> std::declval<_Up>()))
552 if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>)
554 auto __pt =
static_cast<const volatile void*
>(__t);
555 auto __pu =
static_cast<const volatile void*
>(__u);
556 if (std::__is_constant_evaluated())
557 return __pt <=> __pu;
558 auto __it =
reinterpret_cast<__UINTPTR_TYPE__
>(__pt);
559 auto __iu =
reinterpret_cast<__UINTPTR_TYPE__
>(__pu);
560 return __it <=> __iu;
563 return static_cast<_Tp&&
>(__t) <=>
static_cast<_Up&&
>(__u);
566 using is_transparent = void;
573 template<
floating_po
int _Tp>
574 constexpr weak_ordering
575 __fp_weak_ordering(_Tp __e, _Tp __f)
579 auto __cat = [](_Tp __fp) ->
int {
580 const int __sign = __builtin_signbit(__fp) ? -1 : 1;
581 if (__builtin_isnormal(__fp))
582 return (__fp == 0 ? 1 : 3) * __sign;
583 if (__builtin_isnan(__fp))
585 if (
int __inf = __builtin_isinf_sign(__fp))
590 auto __po = __e <=> __f;
592 return weak_ordering::less;
593 else if (is_gt(__po))
594 return weak_ordering::greater;
595 else if (__po == partial_ordering::equivalent)
596 return weak_ordering::equivalent;
600 auto __isnan_sign = [](_Tp __fp) ->
int {
601 return __builtin_isnan(__fp)
602 ? __builtin_signbit(__fp) ? -1 : 1
605 auto __ord = __isnan_sign(__e) <=> __isnan_sign(__f);
607 return weak_ordering::equivalent;
608 else if (is_lt(__ord))
609 return weak_ordering::less;
611 return weak_ordering::greater;
615 void strong_order() =
delete;
617 template<
typename _Tp,
typename _Up>
618 concept __adl_strong =
requires(_Tp&& __t, _Up&& __u)
620 strong_ordering(strong_order(
static_cast<_Tp&&
>(__t),
621 static_cast<_Up&&
>(__u)));
624 void weak_order() =
delete;
626 template<
typename _Tp,
typename _Up>
627 concept __adl_weak =
requires(_Tp&& __t, _Up&& __u)
629 weak_ordering(weak_order(
static_cast<_Tp&&
>(__t),
630 static_cast<_Up&&
>(__u)));
633 void partial_order() =
delete;
635 template<
typename _Tp,
typename _Up>
636 concept __adl_partial =
requires(_Tp&& __t, _Up&& __u)
638 partial_ordering(partial_order(
static_cast<_Tp&&
>(__t),
639 static_cast<_Up&&
>(__u)));
642 template<
typename _Ord,
typename _Tp,
typename _Up>
643 concept __cmp3way =
requires(_Tp&& __t, _Up&& __u, compare_three_way __c)
645 _Ord(__c(
static_cast<_Tp&&
>(__t),
static_cast<_Up&&
>(__u)));
648 template<
typename _Tp,
typename _Up>
649 concept __strongly_ordered
650 = __adl_strong<_Tp, _Up>
651 || floating_point<remove_reference_t<_Tp>>
652 || __cmp3way<strong_ordering, _Tp, _Up>;
654 template<
typename _Tp,
typename _Up>
655 concept __decayed_same_as = same_as<decay_t<_Tp>, decay_t<_Up>>;
659 template<
typename _Tp,
typename _Up>
660 static constexpr bool
663 if constexpr (floating_point<decay_t<_Tp>>)
665 else if constexpr (__adl_strong<_Tp, _Up>)
666 return noexcept(strong_ordering(strong_order(std::declval<_Tp>(),
667 std::declval<_Up>())));
668 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
669 return noexcept(compare_three_way()(std::declval<_Tp>(),
670 std::declval<_Up>()));
673 friend class _Weak_order;
674 friend class _Strong_fallback;
679 _Binary16, _Binary32, _Binary64, _Binary128,
686#ifndef __cpp_using_enum
688 static constexpr _Fp_fmt _Binary16 = _Fp_fmt::_Binary16;
689 static constexpr _Fp_fmt _Binary32 = _Fp_fmt::_Binary32;
690 static constexpr _Fp_fmt _Binary64 = _Fp_fmt::_Binary64;
691 static constexpr _Fp_fmt _Binary128 = _Fp_fmt::_Binary128;
692 static constexpr _Fp_fmt _X86_80bit = _Fp_fmt::_X86_80bit;
693 static constexpr _Fp_fmt _M68k_80bit = _Fp_fmt::_M68k_80bit;
694 static constexpr _Fp_fmt _Dbldbl = _Fp_fmt::_Dbldbl;
695 static constexpr _Fp_fmt _Bfloat16 = _Fp_fmt::_Bfloat16;
699 template<
typename _Tp>
700 static consteval _Fp_fmt
703#ifdef __cpp_using_enum
710#ifdef __LONG_DOUBLE_IBM128__
711 if constexpr (__is_same(_Tp,
long double))
713#elif defined __LONG_DOUBLE_IEEE128__ && defined __SIZEOF_IBM128__
714 if constexpr (__is_same(_Tp, __ibm128))
718#if __LDBL_MANT_DIG__ == 64
719 if constexpr (__is_same(_Tp,
long double))
720 return __LDBL_MIN_EXP__ == -16381 ? _X86_80bit : _M68k_80bit;
722#ifdef __SIZEOF_FLOAT80__
723 if constexpr (__is_same(_Tp, __float80))
726#ifdef __STDCPP_BFLOAT16_T__
727 if constexpr (__is_same(_Tp,
decltype(0.0bf16)))
731 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
733 if constexpr (__width == 16)
735 else if constexpr (__width == 32)
737 else if constexpr (__width == 64)
739 else if constexpr (__width == 128)
744 using int64_t = __INT64_TYPE__;
745 using int32_t = __INT32_TYPE__;
746 using int16_t = __INT16_TYPE__;
747 using uint64_t = __UINT64_TYPE__;
748 using uint16_t = __UINT16_TYPE__;
751 template<
typename _Tp>
754#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
763 _Int(_Tp __hi, uint64_t __lo) noexcept : _M_hi(__hi)
767 _Int(uint64_t __lo) noexcept : _M_hi(0)
770 constexpr bool operator==(
const _Int&)
const =
default;
772#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
777 return _Int(
static_cast<_Tp
>(_M_lo << (__n - 64)), 0);
782 operator^=(
const _Int& __rhs)
noexcept
784 _M_hi ^= __rhs._M_hi;
785 _M_lo ^= __rhs._M_lo;
789 constexpr strong_ordering
790 operator<=>(
const _Int& __rhs)
const noexcept
792 strong_ordering __cmp = _M_hi <=> __rhs._M_hi;
793 if (__cmp != strong_ordering::equal)
795 return _M_lo <=> __rhs._M_lo;
799 template<
typename _Tp>
801 _S_compl(_Tp __t)
noexcept
803 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
805 make_unsigned_t<_Tp> __sign = __t >> (__width - 1);
808 return __t ^ (__sign >> 1);
812 template<
typename _Tp>
813 static constexpr _Int<_Tp>
814 _S_compl(_Int<_Tp> __t)
noexcept
816 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
817 make_unsigned_t<_Tp> __sign = __t._M_hi >> (__width - 1);
818 __t._M_hi ^= (__sign >> 1 );
819 uint64_t __sign64 = (_Tp)__sign;
820 __t._M_lo ^= __sign64;
825 template<
typename _Tp>
826 constexpr static auto
827 _S_fp_bits(_Tp __val)
noexcept
829 if constexpr (
sizeof(_Tp) ==
sizeof(int64_t))
830 return __builtin_bit_cast(int64_t, __val);
831 else if constexpr (
sizeof(_Tp) ==
sizeof(int32_t))
832 return __builtin_bit_cast(int32_t, __val);
833 else if constexpr (
sizeof(_Tp) ==
sizeof(int16_t))
834 return __builtin_bit_cast(int16_t, __val);
837#ifdef __cpp_using_enum
840 constexpr auto __fmt = _S_fp_fmt<_Tp>();
841 if constexpr (__fmt == _X86_80bit || __fmt == _M68k_80bit)
843 if constexpr (
sizeof(_Tp) == 3 *
sizeof(int32_t))
845 auto __ival = __builtin_bit_cast(_Int<int32_t>, __val);
846 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
850 auto __ival = __builtin_bit_cast(_Int<int64_t>, __val);
851 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
854 else if constexpr (
sizeof(_Tp) == 2 *
sizeof(int64_t))
857 return __builtin_bit_cast(__int128, __val);
859 return __builtin_bit_cast(_Int<int64_t>, __val);
863 static_assert(
sizeof(_Tp) ==
sizeof(int64_t),
864 "unsupported floating-point type");
868 template<
typename _Tp>
869 static constexpr strong_ordering
870 _S_fp_cmp(_Tp __x, _Tp __y)
noexcept
873 if (__builtin_isnan(__x) || __builtin_isnan(__y))
875 int __ix = (bool) __builtin_isnan(__x);
876 int __iy = (bool) __builtin_isnan(__y);
877 __ix *= __builtin_signbit(__x) ? -1 : 1;
878 __iy *= __builtin_signbit(__y) ? -1 : 1;
879 return __ix <=> __iy;
882 return __builtin_bit_cast(strong_ordering, __x <=> __y);
885 auto __ix = _S_fp_bits(__x);
886 auto __iy = _S_fp_bits(__y);
889 return strong_ordering::equal;
891#ifdef __cpp_using_enum
894 constexpr auto __fmt = _S_fp_fmt<_Tp>();
896 if constexpr (__fmt == _Dbldbl)
900 struct _Unpacked {
double _M_hi; int64_t _M_lo; };
901 auto __x2 = __builtin_bit_cast(_Unpacked, __x);
902 auto __y2 = __builtin_bit_cast(_Unpacked, __y);
905 auto __cmp = _S_fp_cmp(__x2._M_hi, __y2._M_hi);
906 if (__cmp != strong_ordering::equal)
911 if (__builtin_isnan(__x2._M_hi))
912 return strong_ordering::equal;
915 if (((__x2._M_lo | __y2._M_lo) & 0x7fffffffffffffffULL) == 0)
916 return strong_ordering::equal;
919 return _S_compl(__x2._M_lo) <=> _S_compl(__y2._M_lo);
923 if constexpr (__fmt == _M68k_80bit)
928 constexpr uint16_t __maxexp = 0x7fff;
929 if ((__ix._M_hi & __maxexp) == __maxexp)
930 __ix._M_lo |= 1ull << 63;
931 if ((__iy._M_hi & __maxexp) == __maxexp)
932 __iy._M_lo |= 1ull << 63;
936#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
939 if (__builtin_isnan(__x) && __builtin_isnan(__y))
941 using _Int =
decltype(__ix);
943 constexpr int __nantype = __fmt == _Binary32 ? 22
944 : __fmt == _Binary64 ? 51
945 : __fmt == _Binary128 ? 111
947 constexpr _Int __bit = _Int(1) << __nantype;
953 return _S_compl(__ix) <=> _S_compl(__iy);
958 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
959 requires __strongly_ordered<_Tp, _Up>
960 constexpr strong_ordering
961 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
962 noexcept(_S_noexcept<_Tp, _Up>())
964 if constexpr (floating_point<decay_t<_Tp>>)
965 return _S_fp_cmp(__e, __f);
966 else if constexpr (__adl_strong<_Tp, _Up>)
967 return strong_ordering(strong_order(
static_cast<_Tp&&
>(__e),
968 static_cast<_Up&&
>(__f)));
969 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
970 return compare_three_way()(
static_cast<_Tp&&
>(__e),
971 static_cast<_Up&&
>(__f));
975 template<
typename _Tp,
typename _Up>
976 concept __weakly_ordered
977 = floating_point<remove_reference_t<_Tp>>
978 || __adl_weak<_Tp, _Up>
979 || __cmp3way<weak_ordering, _Tp, _Up>
980 || __strongly_ordered<_Tp, _Up>;
984 template<
typename _Tp,
typename _Up>
985 static constexpr bool
988 if constexpr (floating_point<decay_t<_Tp>>)
990 else if constexpr (__adl_weak<_Tp, _Up>)
991 return noexcept(weak_ordering(weak_order(std::declval<_Tp>(),
992 std::declval<_Up>())));
993 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
994 return noexcept(compare_three_way()(std::declval<_Tp>(),
995 std::declval<_Up>()));
996 else if constexpr (__strongly_ordered<_Tp, _Up>)
997 return _Strong_order::_S_noexcept<_Tp, _Up>();
1000 friend class _Partial_order;
1001 friend class _Weak_fallback;
1004 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1005 requires __weakly_ordered<_Tp, _Up>
1006 constexpr weak_ordering
1007 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1008 noexcept(_S_noexcept<_Tp, _Up>())
1010 if constexpr (floating_point<decay_t<_Tp>>)
1011 return __compare::__fp_weak_ordering(__e, __f);
1012 else if constexpr (__adl_weak<_Tp, _Up>)
1013 return weak_ordering(weak_order(
static_cast<_Tp&&
>(__e),
1014 static_cast<_Up&&
>(__f)));
1015 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
1016 return compare_three_way()(
static_cast<_Tp&&
>(__e),
1017 static_cast<_Up&&
>(__f));
1018 else if constexpr (__strongly_ordered<_Tp, _Up>)
1019 return _Strong_order{}(
static_cast<_Tp&&
>(__e),
1020 static_cast<_Up&&
>(__f));
1024 template<
typename _Tp,
typename _Up>
1025 concept __partially_ordered
1026 = __adl_partial<_Tp, _Up>
1027 || __cmp3way<partial_ordering, _Tp, _Up>
1028 || __weakly_ordered<_Tp, _Up>;
1030 class _Partial_order
1032 template<
typename _Tp,
typename _Up>
1033 static constexpr bool
1036 if constexpr (__adl_partial<_Tp, _Up>)
1037 return noexcept(partial_ordering(partial_order(std::declval<_Tp>(),
1038 std::declval<_Up>())));
1039 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1040 return noexcept(compare_three_way()(std::declval<_Tp>(),
1041 std::declval<_Up>()));
1042 else if constexpr (__weakly_ordered<_Tp, _Up>)
1043 return _Weak_order::_S_noexcept<_Tp, _Up>();
1046 friend class _Partial_fallback;
1049 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1050 requires __partially_ordered<_Tp, _Up>
1051 constexpr partial_ordering
1052 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1053 noexcept(_S_noexcept<_Tp, _Up>())
1055 if constexpr (__adl_partial<_Tp, _Up>)
1056 return partial_ordering(partial_order(
static_cast<_Tp&&
>(__e),
1057 static_cast<_Up&&
>(__f)));
1058 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1059 return compare_three_way()(
static_cast<_Tp&&
>(__e),
1060 static_cast<_Up&&
>(__f));
1061 else if constexpr (__weakly_ordered<_Tp, _Up>)
1062 return _Weak_order{}(
static_cast<_Tp&&
>(__e),
1063 static_cast<_Up&&
>(__f));
1067 template<
typename _Tp,
typename _Up>
1068 concept __op_eq_lt =
requires(_Tp&& __t, _Up&& __u)
1070 {
static_cast<_Tp&&
>(__t) ==
static_cast<_Up&&
>(__u) }
1071 -> convertible_to<bool>;
1072 {
static_cast<_Tp&&
>(__t) <
static_cast<_Up&&
>(__u) }
1073 -> convertible_to<bool>;
1076 class _Strong_fallback
1078 template<
typename _Tp,
typename _Up>
1079 static constexpr bool
1082 if constexpr (__strongly_ordered<_Tp, _Up>)
1083 return _Strong_order::_S_noexcept<_Tp, _Up>();
1085 return noexcept(bool(std::declval<_Tp>() == std::declval<_Up>()))
1086 &&
noexcept(
bool(std::declval<_Tp>() < std::declval<_Up>()));
1090 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1091 requires __strongly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
1092 constexpr strong_ordering
1093 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1094 noexcept(_S_noexcept<_Tp, _Up>())
1096 if constexpr (__strongly_ordered<_Tp, _Up>)
1097 return _Strong_order{}(
static_cast<_Tp&&
>(__e),
1098 static_cast<_Up&&
>(__f));
1100 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1101 ? strong_ordering::equal
1102 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1103 ? strong_ordering::less
1104 : strong_ordering::greater;
1108 class _Weak_fallback
1110 template<
typename _Tp,
typename _Up>
1111 static constexpr bool
1114 if constexpr (__weakly_ordered<_Tp, _Up>)
1115 return _Weak_order::_S_noexcept<_Tp, _Up>();
1117 return noexcept(bool(std::declval<_Tp>() == std::declval<_Up>()))
1118 &&
noexcept(
bool(std::declval<_Tp>() < std::declval<_Up>()));
1122 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1123 requires __weakly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
1124 constexpr weak_ordering
1125 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1126 noexcept(_S_noexcept<_Tp, _Up>())
1128 if constexpr (__weakly_ordered<_Tp, _Up>)
1129 return _Weak_order{}(
static_cast<_Tp&&
>(__e),
1130 static_cast<_Up&&
>(__f));
1132 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1133 ? weak_ordering::equivalent
1134 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1135 ? weak_ordering::less
1136 : weak_ordering::greater;
1142 template<
typename _Tp,
typename _Up>
1143 concept __op_eq_lt_lt = __op_eq_lt<_Tp, _Up>
1144 &&
requires(_Tp&& __t, _Up&& __u)
1146 {
static_cast<_Up&&
>(__u) <
static_cast<_Tp&&
>(__t) }
1147 -> convertible_to<bool>;
1150 class _Partial_fallback
1152 template<
typename _Tp,
typename _Up>
1153 static constexpr bool
1156 if constexpr (__partially_ordered<_Tp, _Up>)
1157 return _Partial_order::_S_noexcept<_Tp, _Up>();
1159 return noexcept(bool(std::declval<_Tp>() == std::declval<_Up>()))
1160 &&
noexcept(
bool(std::declval<_Tp>() < std::declval<_Up>()));
1164 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1165 requires __partially_ordered<_Tp, _Up> || __op_eq_lt_lt<_Tp, _Up>
1166 constexpr partial_ordering
1167 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1168 noexcept(_S_noexcept<_Tp, _Up>())
1170 if constexpr (__partially_ordered<_Tp, _Up>)
1171 return _Partial_order{}(
static_cast<_Tp&&
>(__e),
1172 static_cast<_Up&&
>(__f));
1174 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1175 ? partial_ordering::equivalent
1176 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1177 ? partial_ordering::less
1178 :
static_cast<_Up&&
>(__f) <
static_cast<_Tp&&
>(__e)
1179 ? partial_ordering::greater
1180 : partial_ordering::unordered;
1187 inline namespace _Cpo
1189 inline constexpr __compare::_Strong_order strong_order{};
1191 inline constexpr __compare::_Weak_order weak_order{};
1193 inline constexpr __compare::_Partial_order partial_order{};
1195 inline constexpr __compare::_Strong_fallback
1196 compare_strong_order_fallback{};
1198 inline constexpr __compare::_Weak_fallback
1199 compare_weak_order_fallback{};
1201 inline constexpr __compare::_Partial_fallback
1202 compare_partial_order_fallback{};
1209 inline constexpr struct _Synth3way
1211 template<
typename _Tp,
typename _Up>
1212 static constexpr bool
1213 _S_noexcept(
const _Tp* __t =
nullptr,
const _Up* __u =
nullptr)
1215 if constexpr (three_way_comparable_with<_Tp, _Up>)
1216 return noexcept(*__t <=> *__u);
1218 return noexcept(*__t < *__u) &&
noexcept(*__u < *__t);
1221 template<
typename _Tp,
typename _Up>
1224 operator()(
const _Tp& __t,
const _Up& __u)
const
1225 noexcept(_S_noexcept<_Tp, _Up>())
1228 { __t < __u } -> __boolean_testable;
1229 { __u < __t } -> __boolean_testable;
1232 if constexpr (three_way_comparable_with<_Tp, _Up>)
1237 return weak_ordering::less;
1239 return weak_ordering::greater;
1241 return weak_ordering::equivalent;
1247 template<
typename _Tp,
typename _Up = _Tp>
1249 =
decltype(__detail::__synth3way(std::declval<_Tp&>(),
1250 std::declval<_Up&>()));
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
ISO C++ entities toplevel namespace is std.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
typename __detail::__cmp3way_res_impl< _Tp, _Up >::type compare_three_way_result_t
[cmp.result], result of three-way comparison
[cmp.result], result of three-way comparison