33#pragma GCC system_header
35#if __cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L
40# define __cpp_lib_three_way_comparison 201907L
43namespace std _GLIBCXX_VISIBILITY(default)
49 using type =
signed char;
51 enum class _Ord : type { equivalent = 0, less = -1, greater = 1 };
53 enum class _Ncmp : type { _Unordered = 2 };
57 constexpr __unspec(__unspec*)
noexcept { }
61 class partial_ordering
64 __cmp_cat::type _M_value;
67 partial_ordering(__cmp_cat::_Ord __v) noexcept
68 : _M_value(__cmp_cat::type(__v))
72 partial_ordering(__cmp_cat::_Ncmp __v) noexcept
73 : _M_value(__cmp_cat::type(__v))
76 friend class weak_ordering;
77 friend class strong_ordering;
81 static const partial_ordering less;
82 static const partial_ordering equivalent;
83 static const partial_ordering greater;
84 static const partial_ordering unordered;
89 operator==(partial_ordering __v, __cmp_cat::__unspec)
noexcept
90 {
return __v._M_value == 0; }
94 operator==(partial_ordering, partial_ordering)
noexcept =
default;
98 operator< (partial_ordering __v, __cmp_cat::__unspec)
noexcept
99 {
return __v._M_value == -1; }
102 friend constexpr bool
103 operator> (partial_ordering __v, __cmp_cat::__unspec)
noexcept
104 {
return __v._M_value == 1; }
107 friend constexpr bool
108 operator<=(partial_ordering __v, __cmp_cat::__unspec)
noexcept
109 {
return __v._M_value <= 0; }
112 friend constexpr bool
113 operator>=(partial_ordering __v, __cmp_cat::__unspec)
noexcept
114 {
return __cmp_cat::type(__v._M_value & 1) == __v._M_value; }
117 friend constexpr bool
118 operator< (__cmp_cat::__unspec, partial_ordering __v)
noexcept
119 {
return __v._M_value == 1; }
122 friend constexpr bool
123 operator> (__cmp_cat::__unspec, partial_ordering __v)
noexcept
124 {
return __v._M_value == -1; }
127 friend constexpr bool
128 operator<=(__cmp_cat::__unspec, partial_ordering __v)
noexcept
129 {
return __cmp_cat::type(__v._M_value & 1) == __v._M_value; }
132 friend constexpr bool
133 operator>=(__cmp_cat::__unspec, partial_ordering __v)
noexcept
134 {
return 0 >= __v._M_value; }
137 friend constexpr partial_ordering
138 operator<=>(partial_ordering __v, __cmp_cat::__unspec)
noexcept
142 friend constexpr partial_ordering
143 operator<=>(__cmp_cat::__unspec, partial_ordering __v)
noexcept
145 if (__v._M_value & 1)
146 return partial_ordering(__cmp_cat::_Ord(-__v._M_value));
153 inline constexpr partial_ordering
154 partial_ordering::less(__cmp_cat::_Ord::less);
156 inline constexpr partial_ordering
157 partial_ordering::equivalent(__cmp_cat::_Ord::equivalent);
159 inline constexpr partial_ordering
160 partial_ordering::greater(__cmp_cat::_Ord::greater);
162 inline constexpr partial_ordering
163 partial_ordering::unordered(__cmp_cat::_Ncmp::_Unordered);
167 __cmp_cat::type _M_value;
170 weak_ordering(__cmp_cat::_Ord __v) noexcept : _M_value(__cmp_cat::type(__v))
173 friend class strong_ordering;
177 static const weak_ordering less;
178 static const weak_ordering equivalent;
179 static const weak_ordering greater;
182 constexpr operator partial_ordering() const noexcept
183 {
return partial_ordering(__cmp_cat::_Ord(_M_value)); }
187 friend constexpr bool
188 operator==(weak_ordering __v, __cmp_cat::__unspec)
noexcept
189 {
return __v._M_value == 0; }
192 friend constexpr bool
193 operator==(weak_ordering, weak_ordering)
noexcept =
default;
196 friend constexpr bool
197 operator< (weak_ordering __v, __cmp_cat::__unspec)
noexcept
198 {
return __v._M_value < 0; }
201 friend constexpr bool
202 operator> (weak_ordering __v, __cmp_cat::__unspec)
noexcept
203 {
return __v._M_value > 0; }
206 friend constexpr bool
207 operator<=(weak_ordering __v, __cmp_cat::__unspec)
noexcept
208 {
return __v._M_value <= 0; }
211 friend constexpr bool
212 operator>=(weak_ordering __v, __cmp_cat::__unspec)
noexcept
213 {
return __v._M_value >= 0; }
216 friend constexpr bool
217 operator< (__cmp_cat::__unspec, weak_ordering __v)
noexcept
218 {
return 0 < __v._M_value; }
221 friend constexpr bool
222 operator> (__cmp_cat::__unspec, weak_ordering __v)
noexcept
223 {
return 0 > __v._M_value; }
226 friend constexpr bool
227 operator<=(__cmp_cat::__unspec, weak_ordering __v)
noexcept
228 {
return 0 <= __v._M_value; }
231 friend constexpr bool
232 operator>=(__cmp_cat::__unspec, weak_ordering __v)
noexcept
233 {
return 0 >= __v._M_value; }
236 friend constexpr weak_ordering
237 operator<=>(weak_ordering __v, __cmp_cat::__unspec)
noexcept
241 friend constexpr weak_ordering
242 operator<=>(__cmp_cat::__unspec, weak_ordering __v)
noexcept
243 {
return weak_ordering(__cmp_cat::_Ord(-__v._M_value)); }
247 inline constexpr weak_ordering
248 weak_ordering::less(__cmp_cat::_Ord::less);
250 inline constexpr weak_ordering
251 weak_ordering::equivalent(__cmp_cat::_Ord::equivalent);
253 inline constexpr weak_ordering
254 weak_ordering::greater(__cmp_cat::_Ord::greater);
256 class strong_ordering
258 __cmp_cat::type _M_value;
261 strong_ordering(__cmp_cat::_Ord __v) noexcept
262 : _M_value(__cmp_cat::type(__v))
267 static const strong_ordering less;
268 static const strong_ordering equal;
269 static const strong_ordering equivalent;
270 static const strong_ordering greater;
273 constexpr operator partial_ordering() const noexcept
274 {
return partial_ordering(__cmp_cat::_Ord(_M_value)); }
277 constexpr operator weak_ordering() const noexcept
278 {
return weak_ordering(__cmp_cat::_Ord(_M_value)); }
282 friend constexpr bool
283 operator==(strong_ordering __v, __cmp_cat::__unspec)
noexcept
284 {
return __v._M_value == 0; }
287 friend constexpr bool
288 operator==(strong_ordering, strong_ordering)
noexcept =
default;
291 friend constexpr bool
292 operator< (strong_ordering __v, __cmp_cat::__unspec)
noexcept
293 {
return __v._M_value < 0; }
296 friend constexpr bool
297 operator> (strong_ordering __v, __cmp_cat::__unspec)
noexcept
298 {
return __v._M_value > 0; }
301 friend constexpr bool
302 operator<=(strong_ordering __v, __cmp_cat::__unspec)
noexcept
303 {
return __v._M_value <= 0; }
306 friend constexpr bool
307 operator>=(strong_ordering __v, __cmp_cat::__unspec)
noexcept
308 {
return __v._M_value >= 0; }
311 friend constexpr bool
312 operator< (__cmp_cat::__unspec, strong_ordering __v)
noexcept
313 {
return 0 < __v._M_value; }
316 friend constexpr bool
317 operator> (__cmp_cat::__unspec, strong_ordering __v)
noexcept
318 {
return 0 > __v._M_value; }
321 friend constexpr bool
322 operator<=(__cmp_cat::__unspec, strong_ordering __v)
noexcept
323 {
return 0 <= __v._M_value; }
326 friend constexpr bool
327 operator>=(__cmp_cat::__unspec, strong_ordering __v)
noexcept
328 {
return 0 >= __v._M_value; }
331 friend constexpr strong_ordering
332 operator<=>(strong_ordering __v, __cmp_cat::__unspec)
noexcept
336 friend constexpr strong_ordering
337 operator<=>(__cmp_cat::__unspec, strong_ordering __v)
noexcept
338 {
return strong_ordering(__cmp_cat::_Ord(-__v._M_value)); }
342 inline constexpr strong_ordering
343 strong_ordering::less(__cmp_cat::_Ord::less);
345 inline constexpr strong_ordering
346 strong_ordering::equal(__cmp_cat::_Ord::equivalent);
348 inline constexpr strong_ordering
349 strong_ordering::equivalent(__cmp_cat::_Ord::equivalent);
351 inline constexpr strong_ordering
352 strong_ordering::greater(__cmp_cat::_Ord::greater);
358 is_eq(partial_ordering __cmp)
noexcept
359 {
return __cmp == 0; }
363 is_neq(partial_ordering __cmp)
noexcept
364 {
return __cmp != 0; }
368 is_lt (partial_ordering __cmp)
noexcept
369 {
return __cmp < 0; }
373 is_lteq(partial_ordering __cmp)
noexcept
374 {
return __cmp <= 0; }
378 is_gt (partial_ordering __cmp)
noexcept
379 {
return __cmp > 0; }
383 is_gteq(partial_ordering __cmp)
noexcept
384 {
return __cmp >= 0; }
388 template<
typename _Tp>
389 inline constexpr unsigned __cmp_cat_id = 1;
391 inline constexpr unsigned __cmp_cat_id<partial_ordering> = 2;
393 inline constexpr unsigned __cmp_cat_id<weak_ordering> = 4;
395 inline constexpr unsigned __cmp_cat_id<strong_ordering> = 8;
397 template<
typename... _Ts>
398 constexpr auto __common_cmp_cat()
400 constexpr unsigned __cats = (__cmp_cat_id<_Ts> | ...);
402 if constexpr (__cats & 1)
406 else if constexpr (bool(__cats & __cmp_cat_id<partial_ordering>))
407 return partial_ordering::equivalent;
410 else if constexpr (bool(__cats & __cmp_cat_id<weak_ordering>))
411 return weak_ordering::equivalent;
414 return strong_ordering::equivalent;
419 template<
typename... _Ts>
420 struct common_comparison_category
422 using type =
decltype(__detail::__common_cmp_cat<_Ts...>());
427 template<
typename _Tp>
428 struct common_comparison_category<_Tp>
429 {
using type = void; };
432 struct common_comparison_category<partial_ordering>
433 {
using type = partial_ordering; };
436 struct common_comparison_category<weak_ordering>
437 {
using type = weak_ordering; };
440 struct common_comparison_category<strong_ordering>
441 {
using type = strong_ordering; };
444 struct common_comparison_category<>
445 {
using type = strong_ordering; };
447 template<
typename... _Ts>
448 using common_comparison_category_t
449 =
typename common_comparison_category<_Ts...>::type;
451#if __cpp_lib_concepts
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); }
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;
571 template<
floating_po
int _Tp>
572 constexpr weak_ordering
573 __fp_weak_ordering(_Tp __e, _Tp __f)
577 auto __cat = [](_Tp __fp) ->
int {
578 const int __sign = __builtin_signbit(__fp) ? -1 : 1;
579 if (__builtin_isnormal(__fp))
580 return (__fp == 0 ? 1 : 3) * __sign;
581 if (__builtin_isnan(__fp))
583 if (
int __inf = __builtin_isinf_sign(__fp))
588 auto __po = __e <=> __f;
590 return weak_ordering::less;
591 else if (is_gt(__po))
592 return weak_ordering::greater;
593 else if (__po == partial_ordering::equivalent)
594 return weak_ordering::equivalent;
598 auto __isnan_sign = [](_Tp __fp) ->
int {
599 return __builtin_isnan(__fp)
600 ? __builtin_signbit(__fp) ? -1 : 1
603 auto __ord = __isnan_sign(__e) <=> __isnan_sign(__f);
605 return weak_ordering::equivalent;
606 else if (is_lt(__ord))
607 return weak_ordering::less;
609 return weak_ordering::greater;
613 template<
typename _Tp,
typename _Up>
614 concept __adl_strong =
requires(_Tp&& __t, _Up&& __u)
616 strong_ordering(strong_order(
static_cast<_Tp&&
>(__t),
617 static_cast<_Up&&
>(__u)));
620 template<
typename _Tp,
typename _Up>
621 concept __adl_weak =
requires(_Tp&& __t, _Up&& __u)
623 weak_ordering(weak_order(
static_cast<_Tp&&
>(__t),
624 static_cast<_Up&&
>(__u)));
627 template<
typename _Tp,
typename _Up>
628 concept __adl_partial =
requires(_Tp&& __t, _Up&& __u)
630 partial_ordering(partial_order(
static_cast<_Tp&&
>(__t),
631 static_cast<_Up&&
>(__u)));
634 template<
typename _Ord,
typename _Tp,
typename _Up>
635 concept __cmp3way =
requires(_Tp&& __t, _Up&& __u, compare_three_way __c)
637 _Ord(__c(
static_cast<_Tp&&
>(__t),
static_cast<_Up&&
>(__u)));
640 template<
typename _Tp,
typename _Up>
641 concept __strongly_ordered
642 = __adl_strong<_Tp, _Up>
643 || floating_point<remove_reference_t<_Tp>>
644 || __cmp3way<strong_ordering, _Tp, _Up>;
646 template<
typename _Tp,
typename _Up>
647 concept __decayed_same_as = same_as<decay_t<_Tp>, decay_t<_Up>>;
651 template<
typename _Tp,
typename _Up>
652 static constexpr bool
655 if constexpr (floating_point<decay_t<_Tp>>)
657 else if constexpr (__adl_strong<_Tp, _Up>)
658 return noexcept(strong_ordering(strong_order(std::declval<_Tp>(),
659 std::declval<_Up>())));
660 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
661 return noexcept(compare_three_way()(std::declval<_Tp>(),
662 std::declval<_Up>()));
665 friend class _Weak_order;
666 friend class _Strong_fallback;
671 _Binary16, _Binary32, _Binary64, _Binary128,
678#ifndef __cpp_using_enum
680 static constexpr _Fp_fmt _Binary16 = _Fp_fmt::_Binary16;
681 static constexpr _Fp_fmt _Binary32 = _Fp_fmt::_Binary32;
682 static constexpr _Fp_fmt _Binary64 = _Fp_fmt::_Binary64;
683 static constexpr _Fp_fmt _Binary128 = _Fp_fmt::_Binary128;
684 static constexpr _Fp_fmt _X86_80bit = _Fp_fmt::_X86_80bit;
685 static constexpr _Fp_fmt _M68k_80bit = _Fp_fmt::_M68k_80bit;
686 static constexpr _Fp_fmt _Dbldbl = _Fp_fmt::_Dbldbl;
687 static constexpr _Fp_fmt _Bfloat16 = _Fp_fmt::_Bfloat16;
691 template<
typename _Tp>
692 static consteval _Fp_fmt
695#ifdef __cpp_using_enum
702#ifdef __LONG_DOUBLE_IBM128__
703 if constexpr (__is_same(_Tp,
long double))
705#elif defined __LONG_DOUBLE_IEEE128__ && defined __SIZEOF_IBM128__
706 if constexpr (__is_same(_Tp, __ibm128))
710#if __LDBL_MANT_DIG__ == 64
711 if constexpr (__is_same(_Tp,
long double))
712 return __LDBL_MIN_EXP__ == -16381 ? _X86_80bit : _M68k_80bit;
714#ifdef __SIZEOF_FLOAT80__
715 if constexpr (__is_same(_Tp, __float80))
718#ifdef __STDCPP_BFLOAT16_T__
719 if constexpr (__is_same(_Tp,
decltype(0.0bf16)))
723 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
725 if constexpr (__width == 16)
727 else if constexpr (__width == 32)
729 else if constexpr (__width == 64)
731 else if constexpr (__width == 128)
736 using int64_t = __INT64_TYPE__;
737 using int32_t = __INT32_TYPE__;
738 using int16_t = __INT16_TYPE__;
739 using uint64_t = __UINT64_TYPE__;
740 using uint16_t = __UINT16_TYPE__;
743 template<
typename _Tp>
746#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
755 _Int(_Tp __hi, uint64_t __lo) noexcept : _M_hi(__hi)
759 _Int(uint64_t __lo) noexcept : _M_hi(0)
762 constexpr bool operator==(
const _Int&)
const =
default;
764#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
769 return _Int(
static_cast<_Tp
>(_M_lo << (__n - 64)), 0);
774 operator^=(
const _Int& __rhs)
noexcept
776 _M_hi ^= __rhs._M_hi;
777 _M_lo ^= __rhs._M_lo;
781 constexpr strong_ordering
782 operator<=>(
const _Int& __rhs)
const noexcept
784 strong_ordering __cmp = _M_hi <=> __rhs._M_hi;
785 if (__cmp != strong_ordering::equal)
787 return _M_lo <=> __rhs._M_lo;
791 template<
typename _Tp>
793 _S_compl(_Tp __t)
noexcept
795 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
797 make_unsigned_t<_Tp> __sign = __t >> (__width - 1);
800 return __t ^ (__sign >> 1);
804 template<
typename _Tp>
805 static constexpr _Int<_Tp>
806 _S_compl(_Int<_Tp> __t)
noexcept
808 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
809 make_unsigned_t<_Tp> __sign = __t._M_hi >> (__width - 1);
810 __t._M_hi ^= (__sign >> 1 );
811 uint64_t __sign64 = (_Tp)__sign;
812 __t._M_lo ^= __sign64;
817 template<
typename _Tp>
818 constexpr static auto
819 _S_fp_bits(_Tp __val)
noexcept
821 if constexpr (
sizeof(_Tp) ==
sizeof(int64_t))
822 return __builtin_bit_cast(int64_t, __val);
823 else if constexpr (
sizeof(_Tp) ==
sizeof(int32_t))
824 return __builtin_bit_cast(int32_t, __val);
825 else if constexpr (
sizeof(_Tp) ==
sizeof(int16_t))
826 return __builtin_bit_cast(int16_t, __val);
829#ifdef __cpp_using_enum
832 constexpr auto __fmt = _S_fp_fmt<_Tp>();
833 if constexpr (__fmt == _X86_80bit || __fmt == _M68k_80bit)
835 if constexpr (
sizeof(_Tp) == 3 *
sizeof(int32_t))
837 auto __ival = __builtin_bit_cast(_Int<int32_t>, __val);
838 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
842 auto __ival = __builtin_bit_cast(_Int<int64_t>, __val);
843 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
846 else if constexpr (
sizeof(_Tp) == 2 *
sizeof(int64_t))
849 return __builtin_bit_cast(__int128, __val);
851 return __builtin_bit_cast(_Int<int64_t>, __val);
855 static_assert(
sizeof(_Tp) ==
sizeof(int64_t),
856 "unsupported floating-point type");
860 template<
typename _Tp>
861 static constexpr strong_ordering
862 _S_fp_cmp(_Tp __x, _Tp __y)
noexcept
865 if (__builtin_isnan(__x) || __builtin_isnan(__y))
867 int __ix = (bool) __builtin_isnan(__x);
868 int __iy = (bool) __builtin_isnan(__y);
869 __ix *= __builtin_signbit(__x) ? -1 : 1;
870 __iy *= __builtin_signbit(__y) ? -1 : 1;
871 return __ix <=> __iy;
874 return __builtin_bit_cast(strong_ordering, __x <=> __y);
877 auto __ix = _S_fp_bits(__x);
878 auto __iy = _S_fp_bits(__y);
881 return strong_ordering::equal;
883#ifdef __cpp_using_enum
886 constexpr auto __fmt = _S_fp_fmt<_Tp>();
888 if constexpr (__fmt == _Dbldbl)
892 struct _Unpacked {
double _M_hi; int64_t _M_lo; };
893 auto __x2 = __builtin_bit_cast(_Unpacked, __x);
894 auto __y2 = __builtin_bit_cast(_Unpacked, __y);
897 auto __cmp = _S_fp_cmp(__x2._M_hi, __y2._M_hi);
898 if (__cmp != strong_ordering::equal)
903 if (__builtin_isnan(__x2._M_hi))
904 return strong_ordering::equal;
907 if (((__x2._M_lo | __y2._M_lo) & 0x7fffffffffffffffULL) == 0)
908 return strong_ordering::equal;
911 return _S_compl(__x2._M_lo) <=> _S_compl(__y2._M_lo);
915 if constexpr (__fmt == _M68k_80bit)
920 constexpr uint16_t __maxexp = 0x7fff;
921 if ((__ix._M_hi & __maxexp) == __maxexp)
922 __ix._M_lo |= 1ull << 63;
923 if ((__iy._M_hi & __maxexp) == __maxexp)
924 __iy._M_lo |= 1ull << 63;
928#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
931 if (__builtin_isnan(__x) && __builtin_isnan(__y))
933 using _Int =
decltype(__ix);
935 constexpr int __nantype = __fmt == _Binary32 ? 22
936 : __fmt == _Binary64 ? 51
937 : __fmt == _Binary128 ? 111
939 constexpr _Int __bit = _Int(1) << __nantype;
945 return _S_compl(__ix) <=> _S_compl(__iy);
950 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
951 requires __strongly_ordered<_Tp, _Up>
952 constexpr strong_ordering
953 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
954 noexcept(_S_noexcept<_Tp, _Up>())
956 if constexpr (floating_point<decay_t<_Tp>>)
957 return _S_fp_cmp(__e, __f);
958 else if constexpr (__adl_strong<_Tp, _Up>)
959 return strong_ordering(strong_order(
static_cast<_Tp&&
>(__e),
960 static_cast<_Up&&
>(__f)));
961 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
962 return compare_three_way()(
static_cast<_Tp&&
>(__e),
963 static_cast<_Up&&
>(__f));
967 template<
typename _Tp,
typename _Up>
968 concept __weakly_ordered
969 = floating_point<remove_reference_t<_Tp>>
970 || __adl_weak<_Tp, _Up>
971 || __cmp3way<weak_ordering, _Tp, _Up>
972 || __strongly_ordered<_Tp, _Up>;
976 template<
typename _Tp,
typename _Up>
977 static constexpr bool
980 if constexpr (floating_point<decay_t<_Tp>>)
982 else if constexpr (__adl_weak<_Tp, _Up>)
983 return noexcept(weak_ordering(weak_order(std::declval<_Tp>(),
984 std::declval<_Up>())));
985 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
986 return noexcept(compare_three_way()(std::declval<_Tp>(),
987 std::declval<_Up>()));
988 else if constexpr (__strongly_ordered<_Tp, _Up>)
989 return _Strong_order::_S_noexcept<_Tp, _Up>();
992 friend class _Partial_order;
993 friend class _Weak_fallback;
996 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
997 requires __weakly_ordered<_Tp, _Up>
998 constexpr weak_ordering
999 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1000 noexcept(_S_noexcept<_Tp, _Up>())
1002 if constexpr (floating_point<decay_t<_Tp>>)
1003 return __cmp_cust::__fp_weak_ordering(__e, __f);
1004 else if constexpr (__adl_weak<_Tp, _Up>)
1005 return weak_ordering(weak_order(
static_cast<_Tp&&
>(__e),
1006 static_cast<_Up&&
>(__f)));
1007 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
1008 return compare_three_way()(
static_cast<_Tp&&
>(__e),
1009 static_cast<_Up&&
>(__f));
1010 else if constexpr (__strongly_ordered<_Tp, _Up>)
1011 return _Strong_order{}(
static_cast<_Tp&&
>(__e),
1012 static_cast<_Up&&
>(__f));
1016 template<
typename _Tp,
typename _Up>
1017 concept __partially_ordered
1018 = __adl_partial<_Tp, _Up>
1019 || __cmp3way<partial_ordering, _Tp, _Up>
1020 || __weakly_ordered<_Tp, _Up>;
1022 class _Partial_order
1024 template<
typename _Tp,
typename _Up>
1025 static constexpr bool
1028 if constexpr (__adl_partial<_Tp, _Up>)
1029 return noexcept(partial_ordering(partial_order(std::declval<_Tp>(),
1030 std::declval<_Up>())));
1031 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1032 return noexcept(compare_three_way()(std::declval<_Tp>(),
1033 std::declval<_Up>()));
1034 else if constexpr (__weakly_ordered<_Tp, _Up>)
1035 return _Weak_order::_S_noexcept<_Tp, _Up>();
1038 friend class _Partial_fallback;
1041 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1042 requires __partially_ordered<_Tp, _Up>
1043 constexpr partial_ordering
1044 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1045 noexcept(_S_noexcept<_Tp, _Up>())
1047 if constexpr (__adl_partial<_Tp, _Up>)
1048 return partial_ordering(partial_order(
static_cast<_Tp&&
>(__e),
1049 static_cast<_Up&&
>(__f)));
1050 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1051 return compare_three_way()(
static_cast<_Tp&&
>(__e),
1052 static_cast<_Up&&
>(__f));
1053 else if constexpr (__weakly_ordered<_Tp, _Up>)
1054 return _Weak_order{}(
static_cast<_Tp&&
>(__e),
1055 static_cast<_Up&&
>(__f));
1059 template<
typename _Tp,
typename _Up>
1060 concept __op_eq_lt =
requires(_Tp&& __t, _Up&& __u)
1062 {
static_cast<_Tp&&
>(__t) ==
static_cast<_Up&&
>(__u) }
1063 -> convertible_to<bool>;
1064 {
static_cast<_Tp&&
>(__t) <
static_cast<_Up&&
>(__u) }
1065 -> convertible_to<bool>;
1068 class _Strong_fallback
1070 template<
typename _Tp,
typename _Up>
1071 static constexpr bool
1074 if constexpr (__strongly_ordered<_Tp, _Up>)
1075 return _Strong_order::_S_noexcept<_Tp, _Up>();
1077 return noexcept(bool(std::declval<_Tp>() == std::declval<_Up>()))
1078 &&
noexcept(
bool(std::declval<_Tp>() < std::declval<_Up>()));
1082 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1083 requires __strongly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
1084 constexpr strong_ordering
1085 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1086 noexcept(_S_noexcept<_Tp, _Up>())
1088 if constexpr (__strongly_ordered<_Tp, _Up>)
1089 return _Strong_order{}(
static_cast<_Tp&&
>(__e),
1090 static_cast<_Up&&
>(__f));
1092 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1093 ? strong_ordering::equal
1094 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1095 ? strong_ordering::less
1096 : strong_ordering::greater;
1100 class _Weak_fallback
1102 template<
typename _Tp,
typename _Up>
1103 static constexpr bool
1106 if constexpr (__weakly_ordered<_Tp, _Up>)
1107 return _Weak_order::_S_noexcept<_Tp, _Up>();
1109 return noexcept(bool(std::declval<_Tp>() == std::declval<_Up>()))
1110 &&
noexcept(
bool(std::declval<_Tp>() < std::declval<_Up>()));
1114 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1115 requires __weakly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
1116 constexpr weak_ordering
1117 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1118 noexcept(_S_noexcept<_Tp, _Up>())
1120 if constexpr (__weakly_ordered<_Tp, _Up>)
1121 return _Weak_order{}(
static_cast<_Tp&&
>(__e),
1122 static_cast<_Up&&
>(__f));
1124 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1125 ? weak_ordering::equivalent
1126 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1127 ? weak_ordering::less
1128 : weak_ordering::greater;
1134 template<
typename _Tp,
typename _Up>
1135 concept __op_eq_lt_lt = __op_eq_lt<_Tp, _Up>
1136 &&
requires(_Tp&& __t, _Up&& __u)
1138 {
static_cast<_Up&&
>(__u) <
static_cast<_Tp&&
>(__t) }
1139 -> convertible_to<bool>;
1142 class _Partial_fallback
1144 template<
typename _Tp,
typename _Up>
1145 static constexpr bool
1148 if constexpr (__partially_ordered<_Tp, _Up>)
1149 return _Partial_order::_S_noexcept<_Tp, _Up>();
1151 return noexcept(bool(std::declval<_Tp>() == std::declval<_Up>()))
1152 &&
noexcept(
bool(std::declval<_Tp>() < std::declval<_Up>()));
1156 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1157 requires __partially_ordered<_Tp, _Up> || __op_eq_lt_lt<_Tp, _Up>
1158 constexpr partial_ordering
1159 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1160 noexcept(_S_noexcept<_Tp, _Up>())
1162 if constexpr (__partially_ordered<_Tp, _Up>)
1163 return _Partial_order{}(
static_cast<_Tp&&
>(__e),
1164 static_cast<_Up&&
>(__f));
1166 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1167 ? partial_ordering::equivalent
1168 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1169 ? partial_ordering::less
1170 :
static_cast<_Up&&
>(__f) <
static_cast<_Tp&&
>(__e)
1171 ? partial_ordering::greater
1172 : partial_ordering::unordered;
1178 inline namespace __cmp_alg
1180 inline constexpr __cmp_cust::_Strong_order strong_order{};
1182 inline constexpr __cmp_cust::_Weak_order weak_order{};
1184 inline constexpr __cmp_cust::_Partial_order partial_order{};
1186 inline constexpr __cmp_cust::_Strong_fallback
1187 compare_strong_order_fallback{};
1189 inline constexpr __cmp_cust::_Weak_fallback
1190 compare_weak_order_fallback{};
1192 inline constexpr __cmp_cust::_Partial_fallback
1193 compare_partial_order_fallback{};
1199 inline constexpr struct _Synth3way
1201 template<
typename _Tp,
typename _Up>
1202 static constexpr bool
1203 _S_noexcept(
const _Tp* __t =
nullptr,
const _Up* __u =
nullptr)
1205 if constexpr (three_way_comparable_with<_Tp, _Up>)
1206 return noexcept(*__t <=> *__u);
1208 return noexcept(*__t < *__u) &&
noexcept(*__u < *__t);
1211 template<
typename _Tp,
typename _Up>
1214 operator()(
const _Tp& __t,
const _Up& __u)
const
1215 noexcept(_S_noexcept<_Tp, _Up>())
1218 { __t < __u } -> __boolean_testable;
1219 { __u < __t } -> __boolean_testable;
1222 if constexpr (three_way_comparable_with<_Tp, _Up>)
1227 return weak_ordering::less;
1229 return weak_ordering::greater;
1231 return weak_ordering::equivalent;
1237 template<
typename _Tp,
typename _Up = _Tp>
1239 =
decltype(__detail::__synth3way(std::declval<_Tp&>(),
1240 std::declval<_Up&>()));
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
[concept.convertible], concept convertible_to