33 #pragma GCC system_header
35 #if __cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L
37 #pragma GCC visibility push(default)
41 #if __cpp_lib_concepts
42 # define __cpp_lib_three_way_comparison 201907L
51 using type =
signed char;
53 enum class _Ord : type { equivalent = 0, less = -1, greater = 1 };
55 enum class _Ncmp : type { _Unordered = 2 };
59 constexpr __unspec(__unspec*) noexcept { }
63 class partial_ordering
66 __cmp_cat::type _M_value;
69 partial_ordering(__cmp_cat::_Ord __v) noexcept
70 : _M_value(__cmp_cat::type(__v))
74 partial_ordering(__cmp_cat::_Ncmp __v) noexcept
75 : _M_value(__cmp_cat::type(__v))
78 friend class weak_ordering;
79 friend class strong_ordering;
83 static const partial_ordering less;
84 static const partial_ordering equivalent;
85 static const partial_ordering greater;
86 static const partial_ordering unordered;
91 operator==(partial_ordering __v, __cmp_cat::__unspec) noexcept
92 {
return __v._M_value == 0; }
96 operator==(partial_ordering, partial_ordering) noexcept =
default;
100 operator< (partial_ordering __v, __cmp_cat::__unspec) noexcept
101 {
return __v._M_value == -1; }
104 friend constexpr
bool
105 operator> (partial_ordering __v, __cmp_cat::__unspec) noexcept
106 {
return __v._M_value == 1; }
109 friend constexpr
bool
110 operator<=(partial_ordering __v, __cmp_cat::__unspec) noexcept
111 {
return __v._M_value <= 0; }
114 friend constexpr
bool
115 operator>=(partial_ordering __v, __cmp_cat::__unspec) noexcept
116 {
return __cmp_cat::type(__v._M_value & 1) == __v._M_value; }
119 friend constexpr
bool
120 operator< (__cmp_cat::__unspec, partial_ordering __v) noexcept
121 {
return __v._M_value == 1; }
124 friend constexpr
bool
125 operator> (__cmp_cat::__unspec, partial_ordering __v) noexcept
126 {
return __v._M_value == -1; }
129 friend constexpr
bool
130 operator<=(__cmp_cat::__unspec, partial_ordering __v) noexcept
131 {
return __cmp_cat::type(__v._M_value & 1) == __v._M_value; }
134 friend constexpr
bool
135 operator>=(__cmp_cat::__unspec, partial_ordering __v) noexcept
136 {
return 0 >= __v._M_value; }
139 friend constexpr partial_ordering
140 operator<=>(partial_ordering __v, __cmp_cat::__unspec) noexcept
144 friend constexpr partial_ordering
145 operator<=>(__cmp_cat::__unspec, partial_ordering __v) noexcept
147 if (__v._M_value & 1)
148 return partial_ordering(__cmp_cat::_Ord(-__v._M_value));
155 inline constexpr partial_ordering
156 partial_ordering::less(__cmp_cat::_Ord::less);
158 inline constexpr partial_ordering
159 partial_ordering::equivalent(__cmp_cat::_Ord::equivalent);
161 inline constexpr partial_ordering
162 partial_ordering::greater(__cmp_cat::_Ord::greater);
164 inline constexpr partial_ordering
165 partial_ordering::unordered(__cmp_cat::_Ncmp::_Unordered);
169 __cmp_cat::type _M_value;
172 weak_ordering(__cmp_cat::_Ord __v) noexcept : _M_value(__cmp_cat::type(__v))
175 friend class strong_ordering;
179 static const weak_ordering less;
180 static const weak_ordering equivalent;
181 static const weak_ordering greater;
184 constexpr
operator partial_ordering() const noexcept
185 {
return partial_ordering(__cmp_cat::_Ord(_M_value)); }
189 friend constexpr
bool
190 operator==(weak_ordering __v, __cmp_cat::__unspec) noexcept
191 {
return __v._M_value == 0; }
194 friend constexpr
bool
195 operator==(weak_ordering, weak_ordering) noexcept =
default;
198 friend constexpr
bool
199 operator< (weak_ordering __v, __cmp_cat::__unspec) noexcept
200 {
return __v._M_value < 0; }
203 friend constexpr
bool
204 operator> (weak_ordering __v, __cmp_cat::__unspec) noexcept
205 {
return __v._M_value > 0; }
208 friend constexpr
bool
209 operator<=(weak_ordering __v, __cmp_cat::__unspec) noexcept
210 {
return __v._M_value <= 0; }
213 friend constexpr
bool
214 operator>=(weak_ordering __v, __cmp_cat::__unspec) noexcept
215 {
return __v._M_value >= 0; }
218 friend constexpr
bool
219 operator< (__cmp_cat::__unspec, weak_ordering __v) noexcept
220 {
return 0 < __v._M_value; }
223 friend constexpr
bool
224 operator> (__cmp_cat::__unspec, weak_ordering __v) noexcept
225 {
return 0 > __v._M_value; }
228 friend constexpr
bool
229 operator<=(__cmp_cat::__unspec, weak_ordering __v) noexcept
230 {
return 0 <= __v._M_value; }
233 friend constexpr
bool
234 operator>=(__cmp_cat::__unspec, weak_ordering __v) noexcept
235 {
return 0 >= __v._M_value; }
238 friend constexpr weak_ordering
239 operator<=>(weak_ordering __v, __cmp_cat::__unspec) noexcept
243 friend constexpr weak_ordering
244 operator<=>(__cmp_cat::__unspec, weak_ordering __v) noexcept
245 {
return weak_ordering(__cmp_cat::_Ord(-__v._M_value)); }
249 inline constexpr weak_ordering
250 weak_ordering::less(__cmp_cat::_Ord::less);
252 inline constexpr weak_ordering
253 weak_ordering::equivalent(__cmp_cat::_Ord::equivalent);
255 inline constexpr weak_ordering
256 weak_ordering::greater(__cmp_cat::_Ord::greater);
258 class strong_ordering
260 __cmp_cat::type _M_value;
263 strong_ordering(__cmp_cat::_Ord __v) noexcept
264 : _M_value(__cmp_cat::type(__v))
269 static const strong_ordering less;
270 static const strong_ordering equal;
271 static const strong_ordering equivalent;
272 static const strong_ordering greater;
275 constexpr
operator partial_ordering() const noexcept
276 {
return partial_ordering(__cmp_cat::_Ord(_M_value)); }
279 constexpr
operator weak_ordering() const noexcept
280 {
return weak_ordering(__cmp_cat::_Ord(_M_value)); }
284 friend constexpr
bool
285 operator==(strong_ordering __v, __cmp_cat::__unspec) noexcept
286 {
return __v._M_value == 0; }
289 friend constexpr
bool
290 operator==(strong_ordering, strong_ordering) noexcept =
default;
293 friend constexpr
bool
294 operator< (strong_ordering __v, __cmp_cat::__unspec) noexcept
295 {
return __v._M_value < 0; }
298 friend constexpr
bool
299 operator> (strong_ordering __v, __cmp_cat::__unspec) noexcept
300 {
return __v._M_value > 0; }
303 friend constexpr
bool
304 operator<=(strong_ordering __v, __cmp_cat::__unspec) noexcept
305 {
return __v._M_value <= 0; }
308 friend constexpr
bool
309 operator>=(strong_ordering __v, __cmp_cat::__unspec) noexcept
310 {
return __v._M_value >= 0; }
313 friend constexpr
bool
314 operator< (__cmp_cat::__unspec, strong_ordering __v) noexcept
315 {
return 0 < __v._M_value; }
318 friend constexpr
bool
319 operator> (__cmp_cat::__unspec, strong_ordering __v) noexcept
320 {
return 0 > __v._M_value; }
323 friend constexpr
bool
324 operator<=(__cmp_cat::__unspec, strong_ordering __v) noexcept
325 {
return 0 <= __v._M_value; }
328 friend constexpr
bool
329 operator>=(__cmp_cat::__unspec, strong_ordering __v) noexcept
330 {
return 0 >= __v._M_value; }
333 friend constexpr strong_ordering
334 operator<=>(strong_ordering __v, __cmp_cat::__unspec) noexcept
338 friend constexpr strong_ordering
339 operator<=>(__cmp_cat::__unspec, strong_ordering __v) noexcept
340 {
return strong_ordering(__cmp_cat::_Ord(-__v._M_value)); }
344 inline constexpr strong_ordering
345 strong_ordering::less(__cmp_cat::_Ord::less);
347 inline constexpr strong_ordering
348 strong_ordering::equal(__cmp_cat::_Ord::equivalent);
350 inline constexpr strong_ordering
351 strong_ordering::equivalent(__cmp_cat::_Ord::equivalent);
353 inline constexpr strong_ordering
354 strong_ordering::greater(__cmp_cat::_Ord::greater);
360 is_eq(partial_ordering __cmp) noexcept
361 {
return __cmp == 0; }
365 is_neq(partial_ordering __cmp) noexcept
366 {
return __cmp != 0; }
370 is_lt (partial_ordering __cmp) noexcept
371 {
return __cmp < 0; }
375 is_lteq(partial_ordering __cmp) noexcept
376 {
return __cmp <= 0; }
380 is_gt (partial_ordering __cmp) noexcept
381 {
return __cmp > 0; }
385 is_gteq(partial_ordering __cmp) noexcept
386 {
return __cmp >= 0; }
390 template<
typename _Tp>
391 inline constexpr
unsigned __cmp_cat_id = 1;
393 inline constexpr
unsigned __cmp_cat_id<partial_ordering> = 2;
395 inline constexpr
unsigned __cmp_cat_id<weak_ordering> = 4;
397 inline constexpr
unsigned __cmp_cat_id<strong_ordering> = 8;
399 template<
typename... _Ts>
400 constexpr
auto __common_cmp_cat()
402 constexpr
unsigned __cats = (__cmp_cat_id<_Ts> | ...);
404 if constexpr (__cats & 1)
408 else if constexpr (
bool(__cats & __cmp_cat_id<partial_ordering>))
409 return partial_ordering::equivalent;
412 else if constexpr (
bool(__cats & __cmp_cat_id<weak_ordering>))
413 return weak_ordering::equivalent;
416 return strong_ordering::equivalent;
421 template<
typename... _Ts>
422 struct common_comparison_category
424 using type = decltype(__detail::__common_cmp_cat<_Ts...>());
429 template<
typename _Tp>
430 struct common_comparison_category<_Tp>
431 {
using type = void; };
434 struct common_comparison_category<partial_ordering>
435 {
using type = partial_ordering; };
438 struct common_comparison_category<weak_ordering>
439 {
using type = weak_ordering; };
442 struct common_comparison_category<strong_ordering>
443 {
using type = strong_ordering; };
446 struct common_comparison_category<>
447 {
using type = strong_ordering; };
449 template<
typename... _Ts>
450 using common_comparison_category_t
451 =
typename common_comparison_category<_Ts...>::type;
453 #if __cpp_lib_concepts
456 template<
typename _Tp,
typename _Cat>
457 concept __compares_as
458 = same_as<common_comparison_category_t<_Tp, _Cat>, _Cat>;
462 template<
typename _Tp,
typename _Cat = partial_ordering>
463 concept three_way_comparable
464 = __detail::__weakly_eq_cmp_with<_Tp, _Tp>
465 && __detail::__partially_ordered_with<_Tp, _Tp>
466 && requires(
const remove_reference_t<_Tp>& __a,
467 const remove_reference_t<_Tp>& __b)
469 { __a <=> __b } -> __detail::__compares_as<_Cat>;
472 template<
typename _Tp,
typename _Up,
typename _Cat = partial_ordering>
473 concept three_way_comparable_with
474 = three_way_comparable<_Tp, _Cat>
475 && three_way_comparable<_Up, _Cat>
476 && common_reference_with<const remove_reference_t<_Tp>&,
477 const remove_reference_t<_Up>&>
478 && three_way_comparable<
479 common_reference_t<const remove_reference_t<_Tp>&,
480 const remove_reference_t<_Up>&>, _Cat>
481 && __detail::__weakly_eq_cmp_with<_Tp, _Up>
482 && __detail::__partially_ordered_with<_Tp, _Up>
483 && requires(
const remove_reference_t<_Tp>& __t,
484 const remove_reference_t<_Up>& __u)
486 { __t <=> __u } -> __detail::__compares_as<_Cat>;
487 { __u <=> __t } -> __detail::__compares_as<_Cat>;
492 template<
typename _Tp,
typename _Up>
493 using __cmp3way_res_t
494 = decltype(std::declval<_Tp>() <=> std::declval<_Up>());
501 template<
typename _Tp,
typename _Up>
502 struct __cmp3way_res_impl
505 template<
typename _Tp,
typename _Up>
506 requires requires {
typename __cmp3way_res_t<__cref<_Tp>, __cref<_Up>>; }
507 struct __cmp3way_res_impl<_Tp, _Up>
509 using type = __cmp3way_res_t<__cref<_Tp>, __cref<_Up>>;
514 template<
typename _Tp,
typename _Up = _Tp>
516 : __detail::__cmp3way_res_impl<_Tp, _Up>
520 template<
typename _Tp,
typename _Up = _Tp>
522 =
typename __detail::__cmp3way_res_impl<_Tp, _Up>::type;
530 template<
typename _Tp,
typename _Up>
531 concept __3way_builtin_ptr_cmp
532 = requires(_Tp&& __t, _Up&& __u)
533 {
static_cast<_Tp&&
>(__t) <=>
static_cast<_Up&&
>(__u); }
534 && convertible_to<_Tp, const volatile void*>
535 && convertible_to<_Up, const volatile void*>
536 && ! requires(_Tp&& __t, _Up&& __u)
537 { operator<=>(
static_cast<_Tp&&
>(__t),
static_cast<_Up&&
>(__u)); }
538 && ! requires(_Tp&& __t, _Up&& __u)
539 {
static_cast<_Tp&&
>(__t).operator<=>(
static_cast<_Up&&
>(__u)); };
546 struct compare_three_way
548 template<
typename _Tp,
typename _Up>
549 requires three_way_comparable_with<_Tp, _Up>
551 operator() [[nodiscard]] (_Tp&& __t, _Up&& __u)
const
552 noexcept(noexcept(std::declval<_Tp>() <=> std::declval<_Up>()))
554 if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>)
556 auto __pt =
static_cast<const volatile void*
>(__t);
557 auto __pu =
static_cast<const volatile void*
>(__u);
558 if (std::__is_constant_evaluated())
559 return __pt <=> __pu;
560 auto __it =
reinterpret_cast<__UINTPTR_TYPE__
>(__pt);
561 auto __iu =
reinterpret_cast<__UINTPTR_TYPE__
>(__pu);
562 return __it <=> __iu;
565 return static_cast<_Tp&&
>(__t) <=>
static_cast<_Up&&
>(__u);
568 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 template<
typename _Tp,
typename _Up>
616 concept __adl_strong = requires(_Tp&& __t, _Up&& __u)
618 strong_ordering(strong_order(
static_cast<_Tp&&
>(__t),
619 static_cast<_Up&&
>(__u)));
622 template<
typename _Tp,
typename _Up>
623 concept __adl_weak = requires(_Tp&& __t, _Up&& __u)
625 weak_ordering(weak_order(
static_cast<_Tp&&
>(__t),
626 static_cast<_Up&&
>(__u)));
629 template<
typename _Tp,
typename _Up>
630 concept __adl_partial = requires(_Tp&& __t, _Up&& __u)
632 partial_ordering(partial_order(
static_cast<_Tp&&
>(__t),
633 static_cast<_Up&&
>(__u)));
636 template<
typename _Ord,
typename _Tp,
typename _Up>
637 concept __cmp3way = requires(_Tp&& __t, _Up&& __u, compare_three_way __c)
639 _Ord(__c(
static_cast<_Tp&&
>(__t),
static_cast<_Up&&
>(__u)));
642 template<
typename _Tp,
typename _Up>
643 concept __strongly_ordered
644 = __adl_strong<_Tp, _Up>
645 || floating_point<remove_reference_t<_Tp>>
646 || __cmp3way<strong_ordering, _Tp, _Up>;
648 template<
typename _Tp,
typename _Up>
649 concept __decayed_same_as = same_as<decay_t<_Tp>, decay_t<_Up>>;
653 template<
typename _Tp,
typename _Up>
654 static constexpr
bool
657 if constexpr (floating_point<decay_t<_Tp>>)
659 else if constexpr (__adl_strong<_Tp, _Up>)
660 return noexcept(strong_ordering(strong_order(
std::
declval<_Tp>(),
662 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
663 return noexcept(compare_three_way()(
std::
declval<_Tp>(),
667 friend class _Weak_order;
668 friend class _Strong_fallback;
673 _Binary16, _Binary32, _Binary64, _Binary128,
680 #ifndef __cpp_using_enum
682 static constexpr _Fp_fmt _Binary16 = _Fp_fmt::_Binary16;
683 static constexpr _Fp_fmt _Binary32 = _Fp_fmt::_Binary32;
684 static constexpr _Fp_fmt _Binary64 = _Fp_fmt::_Binary64;
685 static constexpr _Fp_fmt _Binary128 = _Fp_fmt::_Binary128;
686 static constexpr _Fp_fmt _X86_80bit = _Fp_fmt::_X86_80bit;
687 static constexpr _Fp_fmt _M68k_80bit = _Fp_fmt::_M68k_80bit;
688 static constexpr _Fp_fmt _Dbldbl = _Fp_fmt::_Dbldbl;
692 template<
typename _Tp>
693 static consteval _Fp_fmt
696 #ifdef __cpp_using_enum
703 #ifdef __LONG_DOUBLE_IBM128__
704 if constexpr (__is_same(_Tp,
long double))
706 #elif defined __LONG_DOUBLE_IEEE128__ && defined __SIZEOF_IBM128__
707 if constexpr (__is_same(_Tp, __ibm128))
711 #if __LDBL_MANT_DIG__ == 64
712 if constexpr (__is_same(_Tp,
long double))
713 return __LDBL_MIN_EXP__ == -16381 ? _X86_80bit : _M68k_80bit;
715 #ifdef __SIZEOF_FLOAT80__
716 if constexpr (__is_same(_Tp, __float80))
720 constexpr
int __width =
sizeof(_Tp) * __CHAR_BIT__;
722 if constexpr (__width == 16)
724 else if constexpr (__width == 32)
726 else if constexpr (__width == 64)
728 else if constexpr (__width == 128)
733 using int64_t = __INT64_TYPE__;
734 using int32_t = __INT32_TYPE__;
735 using int16_t = __INT16_TYPE__;
736 using uint64_t = __UINT64_TYPE__;
737 using uint16_t = __UINT16_TYPE__;
740 template<typename _Tp>
743 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
752 _Int(_Tp __hi, uint64_t __lo) noexcept : _M_hi(__hi)
756 _Int(uint64_t __lo) noexcept : _M_hi(0)
759 constexpr
bool operator==(
const _Int&)
const =
default;
761 #if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
766 return _Int(
static_cast<_Tp
>(_M_lo << (__n - 64)), 0);
771 operator^=(
const _Int& __rhs) noexcept
773 _M_hi ^= __rhs._M_hi;
774 _M_lo ^= __rhs._M_lo;
778 constexpr strong_ordering
779 operator<=>(
const _Int& __rhs)
const noexcept
781 strong_ordering __cmp = _M_hi <=> __rhs._M_hi;
782 if (__cmp != strong_ordering::equal)
784 return _M_lo <=> __rhs._M_lo;
788 template<
typename _Tp>
790 _S_compl(_Tp __t) noexcept
792 constexpr
int __width =
sizeof(_Tp) * __CHAR_BIT__;
794 make_unsigned_t<_Tp> __sign = __t >> (__width - 1);
797 return __t ^ (__sign >> 1);
801 template<
typename _Tp>
802 static constexpr _Int<_Tp>
803 _S_compl(_Int<_Tp> __t) noexcept
805 constexpr
int __width =
sizeof(_Tp) * __CHAR_BIT__;
806 make_unsigned_t<_Tp> __sign = __t._M_hi >> (__width - 1);
807 __t._M_hi ^= (__sign >> 1 );
808 uint64_t __sign64 = (_Tp)__sign;
809 __t._M_lo ^= __sign64;
814 template<
typename _Tp>
815 constexpr
static auto
816 _S_fp_bits(_Tp __val) noexcept
818 if constexpr (
sizeof(_Tp) ==
sizeof(int64_t))
819 return __builtin_bit_cast(int64_t, __val);
820 else if constexpr (
sizeof(_Tp) ==
sizeof(int32_t))
821 return __builtin_bit_cast(int32_t, __val);
822 else if constexpr (
sizeof(_Tp) ==
sizeof(int16_t))
823 return __builtin_bit_cast(int16_t, __val);
826 #ifdef __cpp_using_enum
829 constexpr
auto __fmt = _S_fp_fmt<_Tp>();
830 if constexpr (__fmt == _X86_80bit || __fmt == _M68k_80bit)
832 if constexpr (
sizeof(_Tp) == 3 *
sizeof(int32_t))
834 auto __ival = __builtin_bit_cast(_Int<int32_t>, __val);
835 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
839 auto __ival = __builtin_bit_cast(_Int<int64_t>, __val);
840 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
843 else if constexpr (
sizeof(_Tp) == 2 *
sizeof(int64_t))
845 #if __SIZEOF_INT128__
846 return __builtin_bit_cast(__int128, __val);
848 return __builtin_bit_cast(_Int<int64_t>, __val);
852 static_assert(
sizeof(_Tp) ==
sizeof(int64_t),
853 "unsupported floating-point type");
857 template<
typename _Tp>
858 static constexpr strong_ordering
859 _S_fp_cmp(_Tp __x, _Tp __y) noexcept
862 if (__builtin_isnan(__x) || __builtin_isnan(__y))
864 int __ix = (bool) __builtin_isnan(__x);
865 int __iy = (bool) __builtin_isnan(__y);
866 __ix *= __builtin_signbit(__x) ? -1 : 1;
867 __iy *= __builtin_signbit(__y) ? -1 : 1;
868 return __ix <=> __iy;
871 return __builtin_bit_cast(strong_ordering, __x <=> __y);
874 auto __ix = _S_fp_bits(__x);
875 auto __iy = _S_fp_bits(__y);
878 return strong_ordering::equal;
880 #ifdef __cpp_using_enum
883 constexpr
auto __fmt = _S_fp_fmt<_Tp>();
885 if constexpr (__fmt == _Dbldbl)
889 struct _Unpacked {
double _M_hi; int64_t _M_lo; };
890 auto __x2 = __builtin_bit_cast(_Unpacked, __x);
891 auto __y2 = __builtin_bit_cast(_Unpacked, __y);
894 auto __cmp = _S_fp_cmp(__x2._M_hi, __y2._M_hi);
895 if (__cmp != strong_ordering::equal)
900 if (__builtin_isnan(__x2._M_hi))
901 return strong_ordering::equal;
904 if (((__x2._M_lo | __y2._M_lo) & 0x7fffffffffffffffULL) == 0)
905 return strong_ordering::equal;
908 return _S_compl(__x2._M_lo) <=> _S_compl(__y2._M_lo);
912 if constexpr (__fmt == _M68k_80bit)
917 constexpr uint16_t __maxexp = 0x7fff;
918 if ((__ix._M_hi & __maxexp) == __maxexp)
919 __ix._M_lo |= 1ull << 63;
920 if ((__iy._M_hi & __maxexp) == __maxexp)
921 __iy._M_lo |= 1ull << 63;
925 #if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
928 if (__builtin_isnan(__x) && __builtin_isnan(__y))
930 using _Int = decltype(__ix);
932 constexpr
int __nantype = __fmt == _Binary32 ? 22
933 : __fmt == _Binary64 ? 51
934 : __fmt == _Binary128 ? 111
936 constexpr _Int __bit = _Int(1) << __nantype;
942 return _S_compl(__ix) <=> _S_compl(__iy);
947 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
948 requires __strongly_ordered<_Tp, _Up>
949 constexpr strong_ordering
950 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
951 noexcept(_S_noexcept<_Tp, _Up>())
953 if constexpr (floating_point<decay_t<_Tp>>)
954 return _S_fp_cmp(__e, __f);
955 else if constexpr (__adl_strong<_Tp, _Up>)
956 return strong_ordering(strong_order(static_cast<_Tp&&>(__e),
957 static_cast<_Up&&>(__f)));
958 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
959 return compare_three_way()(static_cast<_Tp&&>(__e),
960 static_cast<_Up&&>(__f));
964 template<typename _Tp, typename _Up>
965 concept __weakly_ordered
967 || __adl_weak<_Tp, _Up>
968 || __cmp3way<weak_ordering, _Tp, _Up>
969 || __strongly_ordered<_Tp, _Up>;
973 template<
typename _Tp,
typename _Up>
974 static constexpr
bool
977 if constexpr (floating_point<decay_t<_Tp>>)
979 else if constexpr (__adl_weak<_Tp, _Up>)
980 return noexcept(weak_ordering(weak_order(
std::
declval<_Tp>(),
982 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
983 return noexcept(compare_three_way()(
std::
declval<_Tp>(),
985 else if constexpr (__strongly_ordered<_Tp, _Up>)
986 return _Strong_order::_S_noexcept<_Tp, _Up>();
989 friend class _Partial_order;
990 friend class _Weak_fallback;
993 template<typename _Tp, __decayed_same_as<_Tp> _Up>
994 requires __weakly_ordered<_Tp, _Up>
995 constexpr weak_ordering
996 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f) const
997 noexcept(_S_noexcept<_Tp, _Up>())
999 if constexpr (floating_point<decay_t<_Tp>>)
1000 return __cmp_cust::__fp_weak_ordering(__e, __f);
1001 else if constexpr (__adl_weak<_Tp, _Up>)
1002 return weak_ordering(weak_order(static_cast<_Tp&&>(__e),
1003 static_cast<_Up&&>(__f)));
1004 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
1005 return compare_three_way()(static_cast<_Tp&&>(__e),
1006 static_cast<_Up&&>(__f));
1007 else if constexpr (__strongly_ordered<_Tp, _Up>)
1008 return _Strong_order{}(
static_cast<_Tp&&
>(__e),
1009 static_cast<_Up&&
>(__f));
1013 template<
typename _Tp,
typename _Up>
1014 concept __partially_ordered
1015 = __adl_partial<_Tp, _Up>
1016 || __cmp3way<partial_ordering, _Tp, _Up>
1017 || __weakly_ordered<_Tp, _Up>;
1019 class _Partial_order
1021 template<
typename _Tp,
typename _Up>
1022 static constexpr
bool
1025 if constexpr (__adl_partial<_Tp, _Up>)
1026 return noexcept(partial_ordering(partial_order(std::declval<_Tp>(),
1027 std::declval<_Up>())));
1028 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1029 return noexcept(compare_three_way()(std::declval<_Tp>(),
1030 std::declval<_Up>()));
1031 else if constexpr (__weakly_ordered<_Tp, _Up>)
1032 return _Weak_order::_S_noexcept<_Tp, _Up>();
1035 friend class _Partial_fallback;
1038 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1039 requires __partially_ordered<_Tp, _Up>
1040 constexpr partial_ordering
1041 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1042 noexcept(_S_noexcept<_Tp, _Up>())
1044 if constexpr (__adl_partial<_Tp, _Up>)
1045 return partial_ordering(partial_order(
static_cast<_Tp&&
>(__e),
1046 static_cast<_Up&&
>(__f)));
1047 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1048 return compare_three_way()(
static_cast<_Tp&&
>(__e),
1049 static_cast<_Up&&
>(__f));
1050 else if constexpr (__weakly_ordered<_Tp, _Up>)
1051 return _Weak_order{}(
static_cast<_Tp&&
>(__e),
1052 static_cast<_Up&&
>(__f));
1056 template<
typename _Tp,
typename _Up>
1057 concept __op_eq_lt = requires(_Tp&& __t, _Up&& __u)
1059 {
static_cast<_Tp&&
>(__t) ==
static_cast<_Up&&
>(__u) }
1060 -> convertible_to<bool>;
1061 {
static_cast<_Tp&&
>(__t) <
static_cast<_Up&&
>(__u) }
1062 -> convertible_to<bool>;
1065 class _Strong_fallback
1067 template<
typename _Tp,
typename _Up>
1068 static constexpr
bool
1071 if constexpr (__strongly_ordered<_Tp, _Up>)
1072 return _Strong_order::_S_noexcept<_Tp, _Up>();
1074 return noexcept(
bool(std::declval<_Tp>() == std::declval<_Up>()))
1075 && noexcept(
bool(std::declval<_Tp>() < std::declval<_Up>()));
1079 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1080 requires __strongly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
1081 constexpr strong_ordering
1082 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1083 noexcept(_S_noexcept<_Tp, _Up>())
1085 if constexpr (__strongly_ordered<_Tp, _Up>)
1086 return _Strong_order{}(
static_cast<_Tp&&
>(__e),
1087 static_cast<_Up&&
>(__f));
1089 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1090 ? strong_ordering::equal
1091 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1092 ? strong_ordering::less
1093 : strong_ordering::greater;
1097 class _Weak_fallback
1099 template<
typename _Tp,
typename _Up>
1100 static constexpr
bool
1103 if constexpr (__weakly_ordered<_Tp, _Up>)
1104 return _Weak_order::_S_noexcept<_Tp, _Up>();
1106 return noexcept(
bool(std::declval<_Tp>() == std::declval<_Up>()))
1107 && noexcept(
bool(std::declval<_Tp>() < std::declval<_Up>()));
1111 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1112 requires __weakly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
1113 constexpr weak_ordering
1114 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1115 noexcept(_S_noexcept<_Tp, _Up>())
1117 if constexpr (__weakly_ordered<_Tp, _Up>)
1118 return _Weak_order{}(
static_cast<_Tp&&
>(__e),
1119 static_cast<_Up&&
>(__f));
1121 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1122 ? weak_ordering::equivalent
1123 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1124 ? weak_ordering::less
1125 : weak_ordering::greater;
1131 template<
typename _Tp,
typename _Up>
1132 concept __op_eq_lt_lt = __op_eq_lt<_Tp, _Up>
1133 && requires(_Tp&& __t, _Up&& __u)
1135 {
static_cast<_Up&&
>(__u) <
static_cast<_Tp&&
>(__t) }
1136 -> convertible_to<bool>;
1139 class _Partial_fallback
1141 template<
typename _Tp,
typename _Up>
1142 static constexpr
bool
1145 if constexpr (__partially_ordered<_Tp, _Up>)
1146 return _Partial_order::_S_noexcept<_Tp, _Up>();
1148 return noexcept(
bool(std::declval<_Tp>() == std::declval<_Up>()))
1149 && noexcept(
bool(std::declval<_Tp>() < std::declval<_Up>()));
1153 template<
typename _Tp, __decayed_same_as<_Tp> _Up>
1154 requires __partially_ordered<_Tp, _Up> || __op_eq_lt_lt<_Tp, _Up>
1155 constexpr partial_ordering
1156 operator() [[nodiscard]] (_Tp&& __e, _Up&& __f)
const
1157 noexcept(_S_noexcept<_Tp, _Up>())
1159 if constexpr (__partially_ordered<_Tp, _Up>)
1160 return _Partial_order{}(
static_cast<_Tp&&
>(__e),
1161 static_cast<_Up&&
>(__f));
1163 return static_cast<_Tp&&
>(__e) ==
static_cast<_Up&&
>(__f)
1164 ? partial_ordering::equivalent
1165 :
static_cast<_Tp&&
>(__e) <
static_cast<_Up&&
>(__f)
1166 ? partial_ordering::less
1167 :
static_cast<_Up&&
>(__f) <
static_cast<_Tp&&
>(__e)
1168 ? partial_ordering::greater
1169 : partial_ordering::unordered;
1175 inline namespace __cmp_alg
1177 inline constexpr __cmp_cust::_Strong_order strong_order{};
1179 inline constexpr __cmp_cust::_Weak_order weak_order{};
1181 inline constexpr __cmp_cust::_Partial_order partial_order{};
1183 inline constexpr __cmp_cust::_Strong_fallback
1184 compare_strong_order_fallback{};
1186 inline constexpr __cmp_cust::_Weak_fallback
1187 compare_weak_order_fallback{};
1189 inline constexpr __cmp_cust::_Partial_fallback
1190 compare_partial_order_fallback{};
1196 inline constexpr
struct _Synth3way
1198 template<
typename _Tp,
typename _Up>
1199 static constexpr
bool
1200 _S_noexcept(
const _Tp* __t =
nullptr,
const _Up* __u =
nullptr)
1202 if constexpr (three_way_comparable_with<_Tp, _Up>)
1203 return noexcept(*__t <=> *__u);
1205 return noexcept(*__t < *__u) && noexcept(*__u < *__t);
1208 template<
typename _Tp,
typename _Up>
1211 operator()(
const _Tp& __t,
const _Up& __u)
const
1212 noexcept(_S_noexcept<_Tp, _Up>())
1215 { __t < __u } -> __boolean_testable;
1216 { __u < __t } -> __boolean_testable;
1219 if constexpr (three_way_comparable_with<_Tp, _Up>)
1224 return weak_ordering::less;
1226 return weak_ordering::greater;
1228 return weak_ordering::equivalent;
1234 template<
typename _Tp,
typename _Up = _Tp>
1236 = decltype(__detail::__synth3way(std::declval<_Tp&>(),
1237 std::declval<_Up&>()));
1242 #pragma GCC visibility pop
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.
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