34#pragma GCC system_header
37#define __glibcxx_want_three_way_comparison
38#define __glibcxx_want_type_order
41#if __cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L
45#pragma GCC diagnostic push
46#pragma GCC diagnostic ignored "-Wpedantic"
47#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
49namespace std _GLIBCXX_VISIBILITY(default)
55 using type =
signed char;
57 enum class _Ord : type
59 equivalent = 0, less = -1, greater = 1,
61 unordered = -__SCHAR_MAX__ - 1
64 template<
typename _Ordering>
65 [[__gnu__::__always_inline__]]
67 __ord(_Ordering __o)
noexcept
68 {
return _Ord(__o._M_value); }
70 template<
typename _Ordering>
71 [[__gnu__::__always_inline__]]
73 __make(_Ord __o)
noexcept
74 {
return _Ordering(__o); }
78 consteval __literal_zero(__literal_zero*)
noexcept { }
82 class partial_ordering
85 __cmp_cat::type _M_value;
88 partial_ordering(__cmp_cat::_Ord __v) noexcept
89 : _M_value(__cmp_cat::type(__v))
92 [[__gnu__::__always_inline__]]
93 constexpr __cmp_cat::type
97 return static_cast<__cmp_cat::type
>(-_M_value);
100 friend constexpr __cmp_cat::_Ord
101 __cmp_cat::__ord<partial_ordering>(partial_ordering)
noexcept;
102 friend constexpr partial_ordering
103 __cmp_cat::__make<partial_ordering>(__cmp_cat::_Ord)
noexcept;
107 static const partial_ordering less;
108 static const partial_ordering equivalent;
109 static const partial_ordering greater;
110 static const partial_ordering unordered;
114 friend constexpr bool
115 operator==(partial_ordering __v, __cmp_cat::__literal_zero)
noexcept
116 {
return __v._M_value == 0; }
119 friend constexpr bool
120 operator==(partial_ordering, partial_ordering)
noexcept =
default;
123 friend constexpr bool
124 operator< (partial_ordering __v, __cmp_cat::__literal_zero)
noexcept
125 {
return __v._M_value == -1; }
128 friend constexpr bool
129 operator> (partial_ordering __v, __cmp_cat::__literal_zero)
noexcept
130 {
return __v._M_value == 1; }
133 friend constexpr bool
134 operator<=(partial_ordering __v, __cmp_cat::__literal_zero)
noexcept
135 {
return __v._M_reverse() >= 0; }
138 friend constexpr bool
139 operator>=(partial_ordering __v, __cmp_cat::__literal_zero)
noexcept
140 {
return __v._M_value >= 0; }
143 friend constexpr bool
144 operator< (__cmp_cat::__literal_zero, partial_ordering __v)
noexcept
145 {
return __v._M_value == 1; }
148 friend constexpr bool
149 operator> (__cmp_cat::__literal_zero, partial_ordering __v)
noexcept
150 {
return __v._M_value == -1; }
153 friend constexpr bool
154 operator<=(__cmp_cat::__literal_zero, partial_ordering __v)
noexcept
155 {
return 0 <= __v._M_value; }
158 friend constexpr bool
159 operator>=(__cmp_cat::__literal_zero, partial_ordering __v)
noexcept
160 {
return 0 <= __v._M_reverse(); }
163 friend constexpr partial_ordering
164 operator<=>(partial_ordering __v, __cmp_cat::__literal_zero)
noexcept
168 friend constexpr partial_ordering
169 operator<=>(__cmp_cat::__literal_zero, partial_ordering __v)
noexcept
170 {
return partial_ordering(__cmp_cat::_Ord(__v._M_reverse())); }
174 inline constexpr partial_ordering
175 partial_ordering::less(__cmp_cat::_Ord::less);
177 inline constexpr partial_ordering
178 partial_ordering::equivalent(__cmp_cat::_Ord::equivalent);
180 inline constexpr partial_ordering
181 partial_ordering::greater(__cmp_cat::_Ord::greater);
183 inline constexpr partial_ordering
184 partial_ordering::unordered(__cmp_cat::_Ord::unordered);
188 __cmp_cat::type _M_value;
191 weak_ordering(__cmp_cat::_Ord __v) noexcept : _M_value(__cmp_cat::type(__v))
194 friend constexpr __cmp_cat::_Ord
195 __cmp_cat::__ord<weak_ordering>(weak_ordering)
noexcept;
196 friend constexpr weak_ordering
197 __cmp_cat::__make<weak_ordering>(__cmp_cat::_Ord)
noexcept;
201 static const weak_ordering less;
202 static const weak_ordering equivalent;
203 static const weak_ordering greater;
206 constexpr operator partial_ordering() const noexcept
207 {
return __cmp_cat::__make<partial_ordering>(__cmp_cat::_Ord(_M_value)); }
211 friend constexpr bool
212 operator==(weak_ordering __v, __cmp_cat::__literal_zero)
noexcept
213 {
return __v._M_value == 0; }
216 friend constexpr bool
217 operator==(weak_ordering, weak_ordering)
noexcept =
default;
220 friend constexpr bool
221 operator< (weak_ordering __v, __cmp_cat::__literal_zero)
noexcept
222 {
return __v._M_value < 0; }
225 friend constexpr bool
226 operator> (weak_ordering __v, __cmp_cat::__literal_zero)
noexcept
227 {
return __v._M_value > 0; }
230 friend constexpr bool
231 operator<=(weak_ordering __v, __cmp_cat::__literal_zero)
noexcept
232 {
return __v._M_value <= 0; }
235 friend constexpr bool
236 operator>=(weak_ordering __v, __cmp_cat::__literal_zero)
noexcept
237 {
return __v._M_value >= 0; }
240 friend constexpr bool
241 operator< (__cmp_cat::__literal_zero, weak_ordering __v)
noexcept
242 {
return 0 < __v._M_value; }
245 friend constexpr bool
246 operator> (__cmp_cat::__literal_zero, weak_ordering __v)
noexcept
247 {
return 0 > __v._M_value; }
250 friend constexpr bool
251 operator<=(__cmp_cat::__literal_zero, weak_ordering __v)
noexcept
252 {
return 0 <= __v._M_value; }
255 friend constexpr bool
256 operator>=(__cmp_cat::__literal_zero, weak_ordering __v)
noexcept
257 {
return 0 >= __v._M_value; }
260 friend constexpr weak_ordering
261 operator<=>(weak_ordering __v, __cmp_cat::__literal_zero)
noexcept
265 friend constexpr weak_ordering
266 operator<=>(__cmp_cat::__literal_zero, weak_ordering __v)
noexcept
267 {
return weak_ordering(__cmp_cat::_Ord(-__v._M_value)); }
271 inline constexpr weak_ordering
272 weak_ordering::less(__cmp_cat::_Ord::less);
274 inline constexpr weak_ordering
275 weak_ordering::equivalent(__cmp_cat::_Ord::equivalent);
277 inline constexpr weak_ordering
278 weak_ordering::greater(__cmp_cat::_Ord::greater);
280 class strong_ordering
282 __cmp_cat::type _M_value;
285 strong_ordering(__cmp_cat::_Ord __v) noexcept
286 : _M_value(__cmp_cat::type(__v))
289 friend constexpr __cmp_cat::_Ord
290 __cmp_cat::__ord<strong_ordering>(strong_ordering)
noexcept;
291 friend constexpr strong_ordering
292 __cmp_cat::__make<strong_ordering>(__cmp_cat::_Ord)
noexcept;
296 static const strong_ordering less;
297 static const strong_ordering equal;
298 static const strong_ordering equivalent;
299 static const strong_ordering greater;
302 constexpr operator partial_ordering() const noexcept
303 {
return __cmp_cat::__make<partial_ordering>(__cmp_cat::_Ord(_M_value)); }
306 constexpr operator weak_ordering() const noexcept
307 {
return __cmp_cat::__make<weak_ordering>(__cmp_cat::_Ord(_M_value)); }
311 friend constexpr bool
312 operator==(strong_ordering __v, __cmp_cat::__literal_zero)
noexcept
313 {
return __v._M_value == 0; }
316 friend constexpr bool
317 operator==(strong_ordering, strong_ordering)
noexcept =
default;
320 friend constexpr bool
321 operator< (strong_ordering __v, __cmp_cat::__literal_zero)
noexcept
322 {
return __v._M_value < 0; }
325 friend constexpr bool
326 operator> (strong_ordering __v, __cmp_cat::__literal_zero)
noexcept
327 {
return __v._M_value > 0; }
330 friend constexpr bool
331 operator<=(strong_ordering __v, __cmp_cat::__literal_zero)
noexcept
332 {
return __v._M_value <= 0; }
335 friend constexpr bool
336 operator>=(strong_ordering __v, __cmp_cat::__literal_zero)
noexcept
337 {
return __v._M_value >= 0; }
340 friend constexpr bool
341 operator< (__cmp_cat::__literal_zero, strong_ordering __v)
noexcept
342 {
return 0 < __v._M_value; }
345 friend constexpr bool
346 operator> (__cmp_cat::__literal_zero, strong_ordering __v)
noexcept
347 {
return 0 > __v._M_value; }
350 friend constexpr bool
351 operator<=(__cmp_cat::__literal_zero, strong_ordering __v)
noexcept
352 {
return 0 <= __v._M_value; }
355 friend constexpr bool
356 operator>=(__cmp_cat::__literal_zero, strong_ordering __v)
noexcept
357 {
return 0 >= __v._M_value; }
360 friend constexpr strong_ordering
361 operator<=>(strong_ordering __v, __cmp_cat::__literal_zero)
noexcept
365 friend constexpr strong_ordering
366 operator<=>(__cmp_cat::__literal_zero, strong_ordering __v)
noexcept
367 {
return strong_ordering(__cmp_cat::_Ord(-__v._M_value)); }
371 inline constexpr strong_ordering
372 strong_ordering::less(__cmp_cat::_Ord::less);
374 inline constexpr strong_ordering
375 strong_ordering::equal(__cmp_cat::_Ord::equivalent);
377 inline constexpr strong_ordering
378 strong_ordering::equivalent(__cmp_cat::_Ord::equivalent);
380 inline constexpr strong_ordering
381 strong_ordering::greater(__cmp_cat::_Ord::greater);
387 is_eq(partial_ordering __cmp)
noexcept
388 {
return __cmp == 0; }
392 is_neq(partial_ordering __cmp)
noexcept
393 {
return __cmp != 0; }
397 is_lt (partial_ordering __cmp)
noexcept
398 {
return __cmp < 0; }
402 is_lteq(partial_ordering __cmp)
noexcept
403 {
return __cmp <= 0; }
407 is_gt (partial_ordering __cmp)
noexcept
408 {
return __cmp > 0; }
412 is_gteq(partial_ordering __cmp)
noexcept
413 {
return __cmp >= 0; }
417 template<
typename _Tp>
418 inline constexpr unsigned __cmp_cat_id = 1;
420 inline constexpr unsigned __cmp_cat_id<partial_ordering> = 2;
422 inline constexpr unsigned __cmp_cat_id<weak_ordering> = 4;
424 inline constexpr unsigned __cmp_cat_id<strong_ordering> = 8;
426 template<
typename... _Ts>
427 constexpr auto __common_cmp_cat()
429 constexpr unsigned __cats = (__cmp_cat_id<_Ts> | ...);
431 if constexpr (__cats & 1)
435 else if constexpr (bool(__cats & __cmp_cat_id<partial_ordering>))
436 return partial_ordering::equivalent;
439 else if constexpr (bool(__cats & __cmp_cat_id<weak_ordering>))
440 return weak_ordering::equivalent;
443 return strong_ordering::equivalent;
448 template<
typename... _Ts>
449 struct common_comparison_category
451 using type =
decltype(__detail::__common_cmp_cat<_Ts...>());
456 template<
typename _Tp>
457 struct common_comparison_category<_Tp>
458 {
using type = void; };
461 struct common_comparison_category<partial_ordering>
462 {
using type = partial_ordering; };
465 struct common_comparison_category<weak_ordering>
466 {
using type = weak_ordering; };
469 struct common_comparison_category<strong_ordering>
470 {
using type = strong_ordering; };
473 struct common_comparison_category<>
474 {
using type = strong_ordering; };
476 template<
typename... _Ts>
477 using common_comparison_category_t
478 =
typename common_comparison_category<_Ts...>::type;
480#if __cpp_lib_three_way_comparison >= 201907L
484 template<
typename _Tp,
typename _Cat>
485 concept __compares_as
486 = same_as<common_comparison_category_t<_Tp, _Cat>, _Cat>;
490 template<
typename _Tp,
typename _Cat = partial_ordering>
491 concept three_way_comparable
492 = __detail::__weakly_eq_cmp_with<_Tp, _Tp>
493 && __detail::__partially_ordered_with<_Tp, _Tp>
497 { __a <=> __b } -> __detail::__compares_as<_Cat>;
500 template<
typename _Tp,
typename _Up,
typename _Cat = partial_ordering>
501 concept three_way_comparable_with
502 = three_way_comparable<_Tp, _Cat>
503 && three_way_comparable<_Up, _Cat>
504 && common_reference_with<const remove_reference_t<_Tp>&,
506 && three_way_comparable<
509 && __detail::__weakly_eq_cmp_with<_Tp, _Up>
510 && __detail::__partially_ordered_with<_Tp, _Up>
514 { __t <=> __u } -> __detail::__compares_as<_Cat>;
515 { __u <=> __t } -> __detail::__compares_as<_Cat>;
520 template<
typename _Tp,
typename _Up>
521 using __cmp3way_res_t
529 template<
typename _Tp,
typename _Up>
530 struct __cmp3way_res_impl
533 template<
typename _Tp,
typename _Up>
534 requires requires {
typename __cmp3way_res_t<__cref<_Tp>, __cref<_Up>>; }
535 struct __cmp3way_res_impl<_Tp, _Up>
537 using type = __cmp3way_res_t<__cref<_Tp>, __cref<_Up>>;
542 template<
typename _Tp,
typename _Up = _Tp>
544 : __detail::__cmp3way_res_impl<_Tp, _Up>
548 template<
typename _Tp,
typename _Up = _Tp>
550 =
typename __detail::__cmp3way_res_impl<_Tp, _Up>::type;
558 template<
typename _Tp,
typename _Up>
559 concept __3way_builtin_ptr_cmp
560 =
requires(_Tp&& __t, _Up&& __u)
561 {
static_cast<_Tp&&
>(__t) <=>
static_cast<_Up&&
>(__u); }
562 && convertible_to<_Tp, const volatile void*>
563 && convertible_to<_Up, const volatile void*>
564 && !
requires(_Tp&& __t, _Up&& __u)
565 { operator<=>(
static_cast<_Tp&&
>(__t),
static_cast<_Up&&
>(__u)); }
566 && !
requires(_Tp&& __t, _Up&& __u)
567 {
static_cast<_Tp&&
>(__t).operator<=>(
static_cast<_Up&&
>(__u)); };
574 struct compare_three_way
576 template<
typename _Tp,
typename _Up>
577 requires three_way_comparable_with<_Tp, _Up>
579 operator() [[nodiscard]] (_Tp&& __t, _Up&& __u)
const
582 if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>)
584 auto __pt =
static_cast<const volatile void*
>(__t);
585 auto __pu =
static_cast<const volatile void*
>(__u);
586 if (std::__is_constant_evaluated())
587 return __pt <=> __pu;
588 auto __it =
reinterpret_cast<__UINTPTR_TYPE__
>(__pt);
589 auto __iu =
reinterpret_cast<__UINTPTR_TYPE__
>(__pu);
590 return __it <=> __iu;
593 return static_cast<_Tp&&
>(__t) <=>
static_cast<_Up&&
>(__u);
596 using is_transparent = void;
603 template<
floating_po
int _Tp>
604 constexpr weak_ordering
605 __fp_weak_ordering(_Tp __e, _Tp __f)
607 auto __po = __cmp_cat::__ord(__e <=> __f);
608 if (__po != __cmp_cat::_Ord::unordered)
609 return __cmp_cat::__make<weak_ordering>(__po);
613 auto __isnan_sign = [](_Tp __fp) ->
int {
614 return __builtin_isnan(__fp)
615 ? __builtin_signbit(__fp) ? -1 : 1
618 return __isnan_sign(__e) <=> __isnan_sign(__f);
622 void strong_order() =
delete;
624 template<
typename _Tp,
typename _Up>
625 concept __adl_strong =
requires(_Tp&& __t, _Up&& __u)
627 strong_ordering(strong_order(
static_cast<_Tp&&
>(__t),
628 static_cast<_Up&&
>(__u)));
631 void weak_order() =
delete;
633 template<
typename _Tp,
typename _Up>
634 concept __adl_weak =
requires(_Tp&& __t, _Up&& __u)
636 weak_ordering(weak_order(
static_cast<_Tp&&
>(__t),
637 static_cast<_Up&&
>(__u)));
640 void partial_order() =
delete;
642 template<
typename _Tp,
typename _Up>
643 concept __adl_partial =
requires(_Tp&& __t, _Up&& __u)
645 partial_ordering(partial_order(
static_cast<_Tp&&
>(__t),
646 static_cast<_Up&&
>(__u)));
649 template<
typename _Ord,
typename _Tp,
typename _Up>
650 concept __cmp3way =
requires(_Tp&& __t, _Up&& __u, compare_three_way __c)
652 _Ord(__c(
static_cast<_Tp&&
>(__t),
static_cast<_Up&&
>(__u)));
655 template<
typename _Tp,
typename _Up>
656 concept __strongly_ordered
657 = __adl_strong<_Tp, _Up>
658 || floating_point<remove_reference_t<_Tp>>
659 || __cmp3way<strong_ordering, _Tp, _Up>;
661 template<
typename _Tp,
typename _Up>
662 concept __decayed_same_as = same_as<decay_t<_Tp>, decay_t<_Up>>;
666 template<
typename _Tp,
typename _Up>
667 static constexpr bool
670 if constexpr (floating_point<decay_t<_Tp>>)
672 else if constexpr (__adl_strong<_Tp, _Up>)
675 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
680 friend class _Weak_order;
681 friend class _Strong_fallback;
686 _Binary16, _Binary32, _Binary64, _Binary128,
693#ifndef __cpp_using_enum
695 static constexpr _Fp_fmt _Binary16 = _Fp_fmt::_Binary16;
696 static constexpr _Fp_fmt _Binary32 = _Fp_fmt::_Binary32;
697 static constexpr _Fp_fmt _Binary64 = _Fp_fmt::_Binary64;
698 static constexpr _Fp_fmt _Binary128 = _Fp_fmt::_Binary128;
699 static constexpr _Fp_fmt _X86_80bit = _Fp_fmt::_X86_80bit;
700 static constexpr _Fp_fmt _M68k_80bit = _Fp_fmt::_M68k_80bit;
701 static constexpr _Fp_fmt _Dbldbl = _Fp_fmt::_Dbldbl;
702 static constexpr _Fp_fmt _Bfloat16 = _Fp_fmt::_Bfloat16;
706 template<
typename _Tp>
707 static consteval _Fp_fmt
710#ifdef __cpp_using_enum
717#ifdef __LONG_DOUBLE_IBM128__
718 if constexpr (__is_same(_Tp,
long double))
720#elif defined __LONG_DOUBLE_IEEE128__ && defined __SIZEOF_IBM128__
721 if constexpr (__is_same(_Tp, __ibm128))
725#if __LDBL_MANT_DIG__ == 64
726 if constexpr (__is_same(_Tp,
long double))
727 return __LDBL_MIN_EXP__ == -16381 ? _X86_80bit : _M68k_80bit;
729#ifdef __SIZEOF_FLOAT80__
730 if constexpr (__is_same(_Tp, __float80))
733#ifdef __STDCPP_BFLOAT16_T__
734 if constexpr (__is_same(_Tp,
decltype(0.0bf16)))
738 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
740 if constexpr (__width == 16)
742 else if constexpr (__width == 32)
744 else if constexpr (__width == 64)
746 else if constexpr (__width == 128)
751 using int64_t = __INT64_TYPE__;
752 using int32_t = __INT32_TYPE__;
753 using int16_t = __INT16_TYPE__;
754 using uint64_t = __UINT64_TYPE__;
755 using uint16_t = __UINT16_TYPE__;
758 template<
typename _Tp>
761#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
770 _Int(_Tp __hi, uint64_t __lo) noexcept : _M_hi(__hi)
774 _Int(uint64_t __lo) noexcept : _M_hi(0)
777 constexpr bool operator==(
const _Int&)
const =
default;
779#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
784 return _Int(
static_cast<_Tp
>(_M_lo << (__n - 64)), 0);
789 operator^=(
const _Int& __rhs)
noexcept
791 _M_hi ^= __rhs._M_hi;
792 _M_lo ^= __rhs._M_lo;
796 constexpr strong_ordering
797 operator<=>(
const _Int& __rhs)
const noexcept
799 strong_ordering __cmp = _M_hi <=> __rhs._M_hi;
800 if (__cmp != strong_ordering::equal)
802 return _M_lo <=> __rhs._M_lo;
806 template<
typename _Tp>
808 _S_compl(_Tp __t)
noexcept
810 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
812 make_unsigned_t<_Tp> __sign = __t >> (__width - 1);
815 return __t ^ (__sign >> 1);
819 template<
typename _Tp>
820 static constexpr _Int<_Tp>
821 _S_compl(_Int<_Tp> __t)
noexcept
823 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
824 make_unsigned_t<_Tp> __sign = __t._M_hi >> (__width - 1);
825 __t._M_hi ^= (__sign >> 1 );
826 uint64_t __sign64 = (_Tp)__sign;
827 __t._M_lo ^= __sign64;
832 template<
typename _Tp>
833 constexpr static auto
834 _S_fp_bits(_Tp __val)
noexcept
836 if constexpr (
sizeof(_Tp) ==
sizeof(int64_t))
837 return __builtin_bit_cast(int64_t, __val);
838 else if constexpr (
sizeof(_Tp) ==
sizeof(int32_t))
839 return __builtin_bit_cast(int32_t, __val);
840 else if constexpr (
sizeof(_Tp) ==
sizeof(int16_t))
841 return __builtin_bit_cast(int16_t, __val);
844#ifdef __cpp_using_enum
847 constexpr auto __fmt = _S_fp_fmt<_Tp>();
848 if constexpr (__fmt == _X86_80bit)
850 if constexpr (
sizeof(_Tp) == 3 *
sizeof(int32_t))
852 auto __ival = __builtin_bit_cast(_Int<int32_t>, __val);
853 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
857 auto __ival = __builtin_bit_cast(_Int<int64_t>, __val);
858 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
861 else if constexpr (__fmt == _M68k_80bit)
863 auto __ival = __builtin_bit_cast(_Int<int32_t>, __val);
864 return _Int<int16_t>(__ival._M_hi >> 16, __ival._M_lo);
866 else if constexpr (
sizeof(_Tp) == 2 *
sizeof(int64_t))
869 return __builtin_bit_cast(__int128, __val);
871 return __builtin_bit_cast(_Int<int64_t>, __val);
875 static_assert(
sizeof(_Tp) ==
sizeof(int64_t),
876 "unsupported floating-point type");
880 template<
typename _Tp>
881 static constexpr strong_ordering
882 _S_fp_cmp(_Tp __x, _Tp __y)
noexcept
885 if (__builtin_isnan(__x) || __builtin_isnan(__y))
887 int __ix = (bool) __builtin_isnan(__x);
888 int __iy = (bool) __builtin_isnan(__y);
889 __ix *= __builtin_signbit(__x) ? -1 : 1;
890 __iy *= __builtin_signbit(__y) ? -1 : 1;
891 return __ix <=> __iy;
894 return __builtin_bit_cast(strong_ordering, __x <=> __y);
897 auto __ix = _S_fp_bits(__x);
898 auto __iy = _S_fp_bits(__y);
901 return strong_ordering::equal;
903#ifdef __cpp_using_enum
906 constexpr auto __fmt = _S_fp_fmt<_Tp>();
908 if constexpr (__fmt == _Dbldbl)
912 struct _Unpacked {
double _M_hi; int64_t _M_lo; };
913 auto __x2 = __builtin_bit_cast(_Unpacked, __x);
914 auto __y2 = __builtin_bit_cast(_Unpacked, __y);
917 auto __cmp = _S_fp_cmp(__x2._M_hi, __y2._M_hi);
918 if (__cmp != strong_ordering::equal)
923 if (__builtin_isnan(__x2._M_hi))
924 return strong_ordering::equal;
927 if (((__x2._M_lo | __y2._M_lo) & 0x7fffffffffffffffULL) == 0)
928 return strong_ordering::equal;
931 return _S_compl(__x2._M_lo) <=> _S_compl(__y2._M_lo);
935 if constexpr (__fmt == _M68k_80bit)
940 constexpr uint16_t __maxexp = 0x7fff;
941 if ((__ix._M_hi & __maxexp) == __maxexp)
942 __ix._M_lo |= 1ull << 63;
943 if ((__iy._M_hi & __maxexp) == __maxexp)
944 __iy._M_lo |= 1ull << 63;
948#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
951 if (__builtin_isnan(__x) && __builtin_isnan(__y))
953 using _Int =
decltype(__ix);
955 constexpr int __nantype = __fmt == _Binary32 ? 22
956 : __fmt == _Binary64 ? 51
957 : __fmt == _Binary128 ? 111
959 constexpr _Int __bit = _Int(1) << __nantype;
965 return _S_compl(__ix) <=> _S_compl(__iy);
970 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
971 requires __strongly_ordered<_Tp, _Up>
972 constexpr strong_ordering
973 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
974 noexcept(_S_noexcept<_Tp, _Up>())
976 if constexpr (floating_point<decay_t<_Tp>>)
977 return _S_fp_cmp(__e, __f);
978 else if constexpr (__adl_strong<_Tp, _Up>)
979 return strong_ordering(strong_order(
static_cast<_Tp&&
>(__e),
980 static_cast<_Up&&
>(__f)));
981 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
982 return compare_three_way()(
static_cast<_Tp&&
>(__e),
983 static_cast<_Up&&
>(__f));
987 template<
typename _Tp,
typename _Up>
988 concept __weakly_ordered
989 = floating_point<remove_reference_t<_Tp>>
990 || __adl_weak<_Tp, _Up>
991 || __cmp3way<weak_ordering, _Tp, _Up>
992 || __strongly_ordered<_Tp, _Up>;
996 template<
typename _Tp,
typename _Up>
997 static constexpr bool
1000 if constexpr (floating_point<decay_t<_Tp>>)
1002 else if constexpr (__adl_weak<_Tp, _Up>)
1005 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
1008 else if constexpr (__strongly_ordered<_Tp, _Up>)
1009 return _Strong_order::_S_noexcept<_Tp, _Up>();
1012 friend class _Partial_order;
1013 friend class _Weak_fallback;
1016 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1017 requires __weakly_ordered<_Tp, _Up>
1018 constexpr weak_ordering
1019 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1020 noexcept(_S_noexcept<_Tp, _Up>())
1022 if constexpr (floating_point<decay_t<_Tp>>)
1023 return __compare::__fp_weak_ordering(__e, __f);
1024 else if constexpr (__adl_weak<_Tp, _Up>)
1025 return weak_ordering(weak_order(
static_cast<_Tp&&
>(__e),
1026 static_cast<_Up&&
>(__f)));
1027 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
1028 return compare_three_way()(
static_cast<_Tp&&
>(__e),
1029 static_cast<_Up&&
>(__f));
1030 else if constexpr (__strongly_ordered<_Tp, _Up>)
1031 return _Strong_order{}(
static_cast<_Tp&&
>(__e),
1032 static_cast<_Up&&
>(__f));
1036 template<
typename _Tp,
typename _Up>
1037 concept __partially_ordered
1038 = __adl_partial<_Tp, _Up>
1039 || __cmp3way<partial_ordering, _Tp, _Up>
1040 || __weakly_ordered<_Tp, _Up>;
1042 class _Partial_order
1044 template<
typename _Tp,
typename _Up>
1045 static constexpr bool
1048 if constexpr (__adl_partial<_Tp, _Up>)
1051 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1054 else if constexpr (__weakly_ordered<_Tp, _Up>)
1055 return _Weak_order::_S_noexcept<_Tp, _Up>();
1058 friend class _Partial_fallback;
1061 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1062 requires __partially_ordered<_Tp, _Up>
1063 constexpr partial_ordering
1064 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1065 noexcept(_S_noexcept<_Tp, _Up>())
1067 if constexpr (__adl_partial<_Tp, _Up>)
1068 return partial_ordering(partial_order(
static_cast<_Tp&&
>(__e),
1069 static_cast<_Up&&
>(__f)));
1070 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1071 return compare_three_way()(
static_cast<_Tp&&
>(__e),
1072 static_cast<_Up&&
>(__f));
1073 else if constexpr (__weakly_ordered<_Tp, _Up>)
1074 return _Weak_order{}(
static_cast<_Tp&&
>(__e),
1075 static_cast<_Up&&
>(__f));
1079 template<
typename _Tp,
typename _Up>
1080 concept __op_eq_lt =
requires(_Tp&& __t, _Up&& __u)
1082 {
static_cast<_Tp&&
>(__t) ==
static_cast<_Up&&
>(__u) }
1083 -> convertible_to<bool>;
1084 {
static_cast<_Tp&&
>(__t) <
static_cast<_Up&&
>(__u) }
1085 -> convertible_to<bool>;
1088 class _Strong_fallback
1090 template<
typename _Tp,
typename _Up>
1091 static constexpr bool
1094 if constexpr (__strongly_ordered<_Tp, _Up>)
1095 return _Strong_order::_S_noexcept<_Tp, _Up>();
1102 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1103 requires __strongly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
1104 constexpr strong_ordering
1105 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1106 noexcept(_S_noexcept<_Tp, _Up>())
1108 if constexpr (__strongly_ordered<_Tp, _Up>)
1109 return _Strong_order{}(
static_cast<_Tp&&
>(__e),
1110 static_cast<_Up&&
>(__f));
1112 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1113 ? strong_ordering::equal
1114 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1115 ? strong_ordering::less
1116 : strong_ordering::greater;
1120 class _Weak_fallback
1122 template<
typename _Tp,
typename _Up>
1123 static constexpr bool
1126 if constexpr (__weakly_ordered<_Tp, _Up>)
1127 return _Weak_order::_S_noexcept<_Tp, _Up>();
1134 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1135 requires __weakly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
1136 constexpr weak_ordering
1137 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1138 noexcept(_S_noexcept<_Tp, _Up>())
1140 if constexpr (__weakly_ordered<_Tp, _Up>)
1141 return _Weak_order{}(
static_cast<_Tp&&
>(__e),
1142 static_cast<_Up&&
>(__f));
1144 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1145 ? weak_ordering::equivalent
1146 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1147 ? weak_ordering::less
1148 : weak_ordering::greater;
1154 template<
typename _Tp,
typename _Up>
1155 concept __op_eq_lt_lt = __op_eq_lt<_Tp, _Up>
1156 &&
requires(_Tp&& __t, _Up&& __u)
1158 {
static_cast<_Up&&
>(__u) <
static_cast<_Tp&&
>(__t) }
1159 -> convertible_to<bool>;
1162 class _Partial_fallback
1164 template<
typename _Tp,
typename _Up>
1165 static constexpr bool
1168 if constexpr (__partially_ordered<_Tp, _Up>)
1169 return _Partial_order::_S_noexcept<_Tp, _Up>();
1176 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1177 requires __partially_ordered<_Tp, _Up> || __op_eq_lt_lt<_Tp, _Up>
1178 constexpr partial_ordering
1179 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1180 noexcept(_S_noexcept<_Tp, _Up>())
1182 if constexpr (__partially_ordered<_Tp, _Up>)
1183 return _Partial_order{}(
static_cast<_Tp&&
>(__e),
1184 static_cast<_Up&&
>(__f));
1186 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1187 ? partial_ordering::equivalent
1188 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1189 ? partial_ordering::less
1190 :
static_cast<_Up&&
>(__f) <
static_cast<_Tp&&
>(__e)
1191 ? partial_ordering::greater
1192 : partial_ordering::unordered;
1199 inline namespace _Cpo
1201 inline constexpr __compare::_Strong_order strong_order{};
1203 inline constexpr __compare::_Weak_order weak_order{};
1205 inline constexpr __compare::_Partial_order partial_order{};
1207 inline constexpr __compare::_Strong_fallback
1208 compare_strong_order_fallback{};
1210 inline constexpr __compare::_Weak_fallback
1211 compare_weak_order_fallback{};
1213 inline constexpr __compare::_Partial_fallback
1214 compare_partial_order_fallback{};
1221 inline constexpr struct _Synth3way
1223 template<
typename _Tp,
typename _Up>
1224 static constexpr bool
1225 _S_noexcept(
const _Tp* __t =
nullptr,
const _Up* __u =
nullptr)
1227 if constexpr (three_way_comparable_with<_Tp, _Up>)
1228 return noexcept(*__t <=> *__u);
1230 return noexcept(*__t < *__u) &&
noexcept(*__u < *__t);
1233 template<
typename _Tp,
typename _Up>
1236 operator()(
const _Tp& __t,
const _Up& __u)
const
1237 noexcept(_S_noexcept<_Tp, _Up>())
1240 { __t < __u } -> __boolean_testable;
1241 { __u < __t } -> __boolean_testable;
1244 if constexpr (three_way_comparable_with<_Tp, _Up>)
1249 return weak_ordering::less;
1251 return weak_ordering::greater;
1253 return weak_ordering::equivalent;
1259 template<
typename _Tp,
typename _Up = _Tp>
1266#if __glibcxx_type_order >= 202506L
1270 template<
typename _Tp,
typename _Up>
1273 static constexpr strong_ordering value = __builtin_type_order(_Tp, _Up);
1274 using value_type = strong_ordering;
1275 using type = type_order<_Tp, _Up>;
1276 constexpr operator value_type() const noexcept {
return value; }
1277 constexpr value_type operator()() const noexcept {
return value; }
1282 template<
typename _Tp,
typename _Up>
1283 inline constexpr strong_ordering type_order_v
1284 = __builtin_type_order(_Tp, _Up);
1290#pragma GCC diagnostic pop
typename common_reference< _Tp... >::type common_reference_t
typename remove_reference< _Tp >::type remove_reference_t
Alias template for remove_reference.
auto declval() noexcept -> decltype(__declval< _Tp >(0))
ISO C++ entities toplevel namespace is std.
typename __detail::__cmp3way_res_impl< _Tp, _Up >::type compare_three_way_result_t
[cmp.result], result of three-way comparison
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Implementation details not part of the namespace std interface.
[cmp.result], result of three-way comparison