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#pragma GCC diagnostic push
577#pragma GCC diagnostic ignored "-Wc++23-extensions"
578 template<
typename _Tp,
typename _Up>
579 requires three_way_comparable_with<_Tp, _Up>
580 static constexpr auto
581 operator() [[nodiscard]] (_Tp&& __t, _Up&& __u)
584 if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>)
586 auto __pt =
static_cast<const volatile void*
>(__t);
587 auto __pu =
static_cast<const volatile void*
>(__u);
588 if (std::__is_constant_evaluated())
589 return __pt <=> __pu;
590 auto __it =
reinterpret_cast<__UINTPTR_TYPE__
>(__pt);
591 auto __iu =
reinterpret_cast<__UINTPTR_TYPE__
>(__pu);
592 return __it <=> __iu;
595 return static_cast<_Tp&&
>(__t) <=>
static_cast<_Up&&
>(__u);
597#pragma GCC diagnostic pop
599 using is_transparent = void;
606 template<
floating_po
int _Tp>
607 constexpr weak_ordering
608 __fp_weak_ordering(_Tp __e, _Tp __f)
610 auto __po = __cmp_cat::__ord(__e <=> __f);
611 if (__po != __cmp_cat::_Ord::unordered)
612 return __cmp_cat::__make<weak_ordering>(__po);
616 auto __isnan_sign = [](_Tp __fp) ->
int {
617 return __builtin_isnan(__fp)
618 ? __builtin_signbit(__fp) ? -1 : 1
621 return __isnan_sign(__e) <=> __isnan_sign(__f);
625 void strong_order() =
delete;
627 template<
typename _Tp,
typename _Up>
628 concept __adl_strong =
requires(_Tp&& __t, _Up&& __u)
630 strong_ordering(strong_order(
static_cast<_Tp&&
>(__t),
631 static_cast<_Up&&
>(__u)));
634 void weak_order() =
delete;
636 template<
typename _Tp,
typename _Up>
637 concept __adl_weak =
requires(_Tp&& __t, _Up&& __u)
639 weak_ordering(weak_order(
static_cast<_Tp&&
>(__t),
640 static_cast<_Up&&
>(__u)));
643 void partial_order() =
delete;
645 template<
typename _Tp,
typename _Up>
646 concept __adl_partial =
requires(_Tp&& __t, _Up&& __u)
648 partial_ordering(partial_order(
static_cast<_Tp&&
>(__t),
649 static_cast<_Up&&
>(__u)));
652 template<
typename _Ord,
typename _Tp,
typename _Up>
653 concept __cmp3way =
requires(_Tp&& __t, _Up&& __u, compare_three_way __c)
655 _Ord(__c(
static_cast<_Tp&&
>(__t),
static_cast<_Up&&
>(__u)));
658 template<
typename _Tp,
typename _Up>
659 concept __strongly_ordered
660 = __adl_strong<_Tp, _Up>
661 || floating_point<remove_reference_t<_Tp>>
662 || __cmp3way<strong_ordering, _Tp, _Up>;
664 template<
typename _Tp,
typename _Up>
665 concept __decayed_same_as = same_as<decay_t<_Tp>, decay_t<_Up>>;
669 template<
typename _Tp,
typename _Up>
670 static constexpr bool
673 if constexpr (floating_point<decay_t<_Tp>>)
675 else if constexpr (__adl_strong<_Tp, _Up>)
678 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
683 friend class _Weak_order;
684 friend class _Strong_fallback;
689 _Binary16, _Binary32, _Binary64, _Binary128,
696#ifndef __cpp_using_enum
698 static constexpr _Fp_fmt _Binary16 = _Fp_fmt::_Binary16;
699 static constexpr _Fp_fmt _Binary32 = _Fp_fmt::_Binary32;
700 static constexpr _Fp_fmt _Binary64 = _Fp_fmt::_Binary64;
701 static constexpr _Fp_fmt _Binary128 = _Fp_fmt::_Binary128;
702 static constexpr _Fp_fmt _X86_80bit = _Fp_fmt::_X86_80bit;
703 static constexpr _Fp_fmt _M68k_80bit = _Fp_fmt::_M68k_80bit;
704 static constexpr _Fp_fmt _Dbldbl = _Fp_fmt::_Dbldbl;
705 static constexpr _Fp_fmt _Bfloat16 = _Fp_fmt::_Bfloat16;
709 template<
typename _Tp>
710 static consteval _Fp_fmt
713#ifdef __cpp_using_enum
720#ifdef __LONG_DOUBLE_IBM128__
721 if constexpr (__is_same(_Tp,
long double))
723#elif defined __LONG_DOUBLE_IEEE128__ && defined __SIZEOF_IBM128__
724 if constexpr (__is_same(_Tp, __ibm128))
728#if __LDBL_MANT_DIG__ == 64
729 if constexpr (__is_same(_Tp,
long double))
730 return __LDBL_MIN_EXP__ == -16381 ? _X86_80bit : _M68k_80bit;
732#ifdef __SIZEOF_FLOAT80__
733 if constexpr (__is_same(_Tp, __float80))
736#ifdef __STDCPP_BFLOAT16_T__
737 if constexpr (__is_same(_Tp,
decltype(0.0bf16)))
741 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
743 if constexpr (__width == 16)
745 else if constexpr (__width == 32)
747 else if constexpr (__width == 64)
749 else if constexpr (__width == 128)
754 using int64_t = __INT64_TYPE__;
755 using int32_t = __INT32_TYPE__;
756 using int16_t = __INT16_TYPE__;
757 using uint64_t = __UINT64_TYPE__;
758 using uint16_t = __UINT16_TYPE__;
761 template<
typename _Tp>
764#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
773 _Int(_Tp __hi, uint64_t __lo) noexcept : _M_hi(__hi)
777 _Int(uint64_t __lo) noexcept : _M_hi(0)
780 constexpr bool operator==(
const _Int&)
const =
default;
782#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
787 return _Int(
static_cast<_Tp
>(_M_lo << (__n - 64)), 0);
792 operator^=(
const _Int& __rhs)
noexcept
794 _M_hi ^= __rhs._M_hi;
795 _M_lo ^= __rhs._M_lo;
799 constexpr strong_ordering
800 operator<=>(
const _Int& __rhs)
const noexcept
802 strong_ordering __cmp = _M_hi <=> __rhs._M_hi;
803 if (__cmp != strong_ordering::equal)
805 return _M_lo <=> __rhs._M_lo;
809 template<
typename _Tp>
811 _S_compl(_Tp __t)
noexcept
813 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
815 make_unsigned_t<_Tp> __sign = __t >> (__width - 1);
818 return __t ^ (__sign >> 1);
822 template<
typename _Tp>
823 static constexpr _Int<_Tp>
824 _S_compl(_Int<_Tp> __t)
noexcept
826 constexpr int __width =
sizeof(_Tp) * __CHAR_BIT__;
827 make_unsigned_t<_Tp> __sign = __t._M_hi >> (__width - 1);
828 __t._M_hi ^= (__sign >> 1 );
829 uint64_t __sign64 = (_Tp)__sign;
830 __t._M_lo ^= __sign64;
835 template<
typename _Tp>
836 constexpr static auto
837 _S_fp_bits(_Tp __val)
noexcept
839 if constexpr (
sizeof(_Tp) ==
sizeof(int64_t))
840 return __builtin_bit_cast(int64_t, __val);
841 else if constexpr (
sizeof(_Tp) ==
sizeof(int32_t))
842 return __builtin_bit_cast(int32_t, __val);
843 else if constexpr (
sizeof(_Tp) ==
sizeof(int16_t))
844 return __builtin_bit_cast(int16_t, __val);
847#ifdef __cpp_using_enum
850 constexpr auto __fmt = _S_fp_fmt<_Tp>();
851 if constexpr (__fmt == _X86_80bit)
853 if constexpr (
sizeof(_Tp) == 3 *
sizeof(int32_t))
855 auto __ival = __builtin_bit_cast(_Int<int32_t>, __val);
856 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
860 auto __ival = __builtin_bit_cast(_Int<int64_t>, __val);
861 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
864 else if constexpr (__fmt == _M68k_80bit)
866 auto __ival = __builtin_bit_cast(_Int<int32_t>, __val);
867 return _Int<int16_t>(__ival._M_hi >> 16, __ival._M_lo);
869 else if constexpr (
sizeof(_Tp) == 2 *
sizeof(int64_t))
872 return __builtin_bit_cast(__int128, __val);
874 return __builtin_bit_cast(_Int<int64_t>, __val);
878 static_assert(
sizeof(_Tp) ==
sizeof(int64_t),
879 "unsupported floating-point type");
883 template<
typename _Tp>
884 static constexpr strong_ordering
885 _S_fp_cmp(_Tp __x, _Tp __y)
noexcept
888 if (__builtin_isnan(__x) || __builtin_isnan(__y))
890 int __ix = (bool) __builtin_isnan(__x);
891 int __iy = (bool) __builtin_isnan(__y);
892 __ix *= __builtin_signbit(__x) ? -1 : 1;
893 __iy *= __builtin_signbit(__y) ? -1 : 1;
894 return __ix <=> __iy;
897 return __builtin_bit_cast(strong_ordering, __x <=> __y);
900 auto __ix = _S_fp_bits(__x);
901 auto __iy = _S_fp_bits(__y);
904 return strong_ordering::equal;
906#ifdef __cpp_using_enum
909 constexpr auto __fmt = _S_fp_fmt<_Tp>();
911 if constexpr (__fmt == _Dbldbl)
915 struct _Unpacked {
double _M_hi; int64_t _M_lo; };
916 auto __x2 = __builtin_bit_cast(_Unpacked, __x);
917 auto __y2 = __builtin_bit_cast(_Unpacked, __y);
920 auto __cmp = _S_fp_cmp(__x2._M_hi, __y2._M_hi);
921 if (__cmp != strong_ordering::equal)
926 if (__builtin_isnan(__x2._M_hi))
927 return strong_ordering::equal;
930 if (((__x2._M_lo | __y2._M_lo) & 0x7fffffffffffffffULL) == 0)
931 return strong_ordering::equal;
934 return _S_compl(__x2._M_lo) <=> _S_compl(__y2._M_lo);
938 if constexpr (__fmt == _M68k_80bit)
943 constexpr uint16_t __maxexp = 0x7fff;
944 if ((__ix._M_hi & __maxexp) == __maxexp)
945 __ix._M_lo |= 1ull << 63;
946 if ((__iy._M_hi & __maxexp) == __maxexp)
947 __iy._M_lo |= 1ull << 63;
951#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
954 if (__builtin_isnan(__x) && __builtin_isnan(__y))
956 using _Int =
decltype(__ix);
958 constexpr int __nantype = __fmt == _Binary32 ? 22
959 : __fmt == _Binary64 ? 51
960 : __fmt == _Binary128 ? 111
962 constexpr _Int __bit = _Int(1) << __nantype;
968 return _S_compl(__ix) <=> _S_compl(__iy);
973 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
974 requires __strongly_ordered<_Tp, _Up>
975 constexpr strong_ordering
976 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
977 noexcept(_S_noexcept<_Tp, _Up>())
979 if constexpr (floating_point<decay_t<_Tp>>)
980 return _S_fp_cmp(__e, __f);
981 else if constexpr (__adl_strong<_Tp, _Up>)
982 return strong_ordering(strong_order(
static_cast<_Tp&&
>(__e),
983 static_cast<_Up&&
>(__f)));
984 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
985 return compare_three_way()(
static_cast<_Tp&&
>(__e),
986 static_cast<_Up&&
>(__f));
990 template<
typename _Tp,
typename _Up>
991 concept __weakly_ordered
992 = floating_point<remove_reference_t<_Tp>>
993 || __adl_weak<_Tp, _Up>
994 || __cmp3way<weak_ordering, _Tp, _Up>
995 || __strongly_ordered<_Tp, _Up>;
999 template<
typename _Tp,
typename _Up>
1000 static constexpr bool
1003 if constexpr (floating_point<decay_t<_Tp>>)
1005 else if constexpr (__adl_weak<_Tp, _Up>)
1008 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
1011 else if constexpr (__strongly_ordered<_Tp, _Up>)
1012 return _Strong_order::_S_noexcept<_Tp, _Up>();
1015 friend class _Partial_order;
1016 friend class _Weak_fallback;
1019 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1020 requires __weakly_ordered<_Tp, _Up>
1021 constexpr weak_ordering
1022 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1023 noexcept(_S_noexcept<_Tp, _Up>())
1025 if constexpr (floating_point<decay_t<_Tp>>)
1026 return __compare::__fp_weak_ordering(__e, __f);
1027 else if constexpr (__adl_weak<_Tp, _Up>)
1028 return weak_ordering(weak_order(
static_cast<_Tp&&
>(__e),
1029 static_cast<_Up&&
>(__f)));
1030 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
1031 return compare_three_way()(
static_cast<_Tp&&
>(__e),
1032 static_cast<_Up&&
>(__f));
1033 else if constexpr (__strongly_ordered<_Tp, _Up>)
1034 return _Strong_order{}(
static_cast<_Tp&&
>(__e),
1035 static_cast<_Up&&
>(__f));
1039 template<
typename _Tp,
typename _Up>
1040 concept __partially_ordered
1041 = __adl_partial<_Tp, _Up>
1042 || __cmp3way<partial_ordering, _Tp, _Up>
1043 || __weakly_ordered<_Tp, _Up>;
1045 class _Partial_order
1047 template<
typename _Tp,
typename _Up>
1048 static constexpr bool
1051 if constexpr (__adl_partial<_Tp, _Up>)
1054 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1057 else if constexpr (__weakly_ordered<_Tp, _Up>)
1058 return _Weak_order::_S_noexcept<_Tp, _Up>();
1061 friend class _Partial_fallback;
1064 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1065 requires __partially_ordered<_Tp, _Up>
1066 constexpr partial_ordering
1067 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1068 noexcept(_S_noexcept<_Tp, _Up>())
1070 if constexpr (__adl_partial<_Tp, _Up>)
1071 return partial_ordering(partial_order(
static_cast<_Tp&&
>(__e),
1072 static_cast<_Up&&
>(__f)));
1073 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1074 return compare_three_way()(
static_cast<_Tp&&
>(__e),
1075 static_cast<_Up&&
>(__f));
1076 else if constexpr (__weakly_ordered<_Tp, _Up>)
1077 return _Weak_order{}(
static_cast<_Tp&&
>(__e),
1078 static_cast<_Up&&
>(__f));
1082 template<
typename _Tp,
typename _Up>
1083 concept __op_eq_lt =
requires(_Tp&& __t, _Up&& __u)
1085 {
static_cast<_Tp&&
>(__t) ==
static_cast<_Up&&
>(__u) }
1086 -> convertible_to<bool>;
1087 {
static_cast<_Tp&&
>(__t) <
static_cast<_Up&&
>(__u) }
1088 -> convertible_to<bool>;
1091 class _Strong_fallback
1093 template<
typename _Tp,
typename _Up>
1094 static constexpr bool
1097 if constexpr (__strongly_ordered<_Tp, _Up>)
1098 return _Strong_order::_S_noexcept<_Tp, _Up>();
1105 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1106 requires __strongly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
1107 constexpr strong_ordering
1108 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1109 noexcept(_S_noexcept<_Tp, _Up>())
1111 if constexpr (__strongly_ordered<_Tp, _Up>)
1112 return _Strong_order{}(
static_cast<_Tp&&
>(__e),
1113 static_cast<_Up&&
>(__f));
1115 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1116 ? strong_ordering::equal
1117 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1118 ? strong_ordering::less
1119 : strong_ordering::greater;
1123 class _Weak_fallback
1125 template<
typename _Tp,
typename _Up>
1126 static constexpr bool
1129 if constexpr (__weakly_ordered<_Tp, _Up>)
1130 return _Weak_order::_S_noexcept<_Tp, _Up>();
1137 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1138 requires __weakly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
1139 constexpr weak_ordering
1140 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1141 noexcept(_S_noexcept<_Tp, _Up>())
1143 if constexpr (__weakly_ordered<_Tp, _Up>)
1144 return _Weak_order{}(
static_cast<_Tp&&
>(__e),
1145 static_cast<_Up&&
>(__f));
1147 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1148 ? weak_ordering::equivalent
1149 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1150 ? weak_ordering::less
1151 : weak_ordering::greater;
1157 template<
typename _Tp,
typename _Up>
1158 concept __op_eq_lt_lt = __op_eq_lt<_Tp, _Up>
1159 &&
requires(_Tp&& __t, _Up&& __u)
1161 {
static_cast<_Up&&
>(__u) <
static_cast<_Tp&&
>(__t) }
1162 -> convertible_to<bool>;
1165 class _Partial_fallback
1167 template<
typename _Tp,
typename _Up>
1168 static constexpr bool
1171 if constexpr (__partially_ordered<_Tp, _Up>)
1172 return _Partial_order::_S_noexcept<_Tp, _Up>();
1179 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1180 requires __partially_ordered<_Tp, _Up> || __op_eq_lt_lt<_Tp, _Up>
1181 constexpr partial_ordering
1182 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1183 noexcept(_S_noexcept<_Tp, _Up>())
1185 if constexpr (__partially_ordered<_Tp, _Up>)
1186 return _Partial_order{}(
static_cast<_Tp&&
>(__e),
1187 static_cast<_Up&&
>(__f));
1189 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1190 ? partial_ordering::equivalent
1191 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1192 ? partial_ordering::less
1193 :
static_cast<_Up&&
>(__f) <
static_cast<_Tp&&
>(__e)
1194 ? partial_ordering::greater
1195 : partial_ordering::unordered;
1202 inline namespace _Cpo
1204 inline constexpr __compare::_Strong_order strong_order{};
1206 inline constexpr __compare::_Weak_order weak_order{};
1208 inline constexpr __compare::_Partial_order partial_order{};
1210 inline constexpr __compare::_Strong_fallback
1211 compare_strong_order_fallback{};
1213 inline constexpr __compare::_Weak_fallback
1214 compare_weak_order_fallback{};
1216 inline constexpr __compare::_Partial_fallback
1217 compare_partial_order_fallback{};
1224 inline constexpr struct _Synth3way
1226 template<
typename _Tp,
typename _Up>
1227 static constexpr bool
1228 _S_noexcept(
const _Tp* __t =
nullptr,
const _Up* __u =
nullptr)
1230 if constexpr (three_way_comparable_with<_Tp, _Up>)
1231 return noexcept(*__t <=> *__u);
1233 return noexcept(*__t < *__u) &&
noexcept(*__u < *__t);
1236 template<
typename _Tp,
typename _Up>
1239 operator()(
const _Tp& __t,
const _Up& __u)
const
1240 noexcept(_S_noexcept<_Tp, _Up>())
1243 { __t < __u } -> __boolean_testable;
1244 { __u < __t } -> __boolean_testable;
1247 if constexpr (three_way_comparable_with<_Tp, _Up>)
1252 return weak_ordering::less;
1254 return weak_ordering::greater;
1256 return weak_ordering::equivalent;
1262 template<
typename _Tp,
typename _Up = _Tp>
1269#if __glibcxx_type_order >= 202506L
1273 template<
typename _Tp,
typename _Up>
1276 static constexpr strong_ordering value = __builtin_type_order(_Tp, _Up);
1277 using value_type = strong_ordering;
1278 constexpr operator value_type() const noexcept {
return value; }
1279 constexpr value_type operator()() const noexcept {
return value; }
1284 template<
typename _Tp,
typename _Up>
1285 inline constexpr strong_ordering type_order_v
1286 = __builtin_type_order(_Tp, _Up);
1292#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