libstdc++
compare
Go to the documentation of this file.
1// -*- C++ -*- operator<=> three-way comparison support.
2
3// Copyright (C) 2019-2025 Free Software Foundation, Inc.
4//
5// This file is part of GCC.
6//
7// GCC is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 3, or (at your option)
10// any later version.
11//
12// GCC is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// Under Section 7 of GPL version 3, you are granted additional
18// permissions described in the GCC Runtime Library Exception, version
19// 3.1, as published by the Free Software Foundation.
20
21// You should have received a copy of the GNU General Public License and
22// a copy of the GCC Runtime Library Exception along with this program;
23// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24// <http://www.gnu.org/licenses/>.
25
26/** @file compare
27 * This is a Standard C++ Library header.
28 */
29
30#ifndef _COMPARE
31#define _COMPARE
32
33#ifdef _GLIBCXX_SYSHDR
34#pragma GCC system_header
35#endif
36
37#define __glibcxx_want_three_way_comparison
38#define __glibcxx_want_type_order
39#include <bits/version.h>
40
41#if __cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L
42
43#include <concepts>
44
45#pragma GCC diagnostic push
46#pragma GCC diagnostic ignored "-Wpedantic" // __int128
47#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
48
49namespace std _GLIBCXX_VISIBILITY(default)
50{
51 // [cmp.categories], comparison category types
52
53 namespace __cmp_cat
54 {
55 using type = signed char;
56
57 enum class _Ord : type
58 {
59 equivalent = 0, less = -1, greater = 1,
60 // value remains unchanged when negated
61 unordered = -__SCHAR_MAX__ - 1
62 };
63
64 template<typename _Ordering>
65 [[__gnu__::__always_inline__]]
66 constexpr _Ord
67 __ord(_Ordering __o) noexcept
68 { return _Ord(__o._M_value); }
69
70 template<typename _Ordering>
71 [[__gnu__::__always_inline__]]
72 constexpr _Ordering
73 __make(_Ord __o) noexcept
74 { return _Ordering(__o); }
75
76 struct __literal_zero
77 {
78 consteval __literal_zero(__literal_zero*) noexcept { }
79 };
80 }
81
82 class partial_ordering
83 {
84 // less=0xff, equiv=0x00, greater=0x01, unordered=0x80
85 __cmp_cat::type _M_value;
86
87 constexpr explicit
88 partial_ordering(__cmp_cat::_Ord __v) noexcept
89 : _M_value(__cmp_cat::type(__v))
90 { }
91
92 [[__gnu__::__always_inline__]]
93 constexpr __cmp_cat::type
94 _M_reverse() const
95 {
96 // leaves _Ord::unordered unchanged
97 return static_cast<__cmp_cat::type>(-_M_value);
98 }
99
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;
104
105 public:
106 // valid values
107 static const partial_ordering less;
108 static const partial_ordering equivalent;
109 static const partial_ordering greater;
110 static const partial_ordering unordered;
111
112 // comparisons
113 [[nodiscard]]
114 friend constexpr bool
115 operator==(partial_ordering __v, __cmp_cat::__literal_zero) noexcept
116 { return __v._M_value == 0; }
117
118 [[nodiscard]]
119 friend constexpr bool
120 operator==(partial_ordering, partial_ordering) noexcept = default;
121
122 [[nodiscard]]
123 friend constexpr bool
124 operator< (partial_ordering __v, __cmp_cat::__literal_zero) noexcept
125 { return __v._M_value == -1; }
126
127 [[nodiscard]]
128 friend constexpr bool
129 operator> (partial_ordering __v, __cmp_cat::__literal_zero) noexcept
130 { return __v._M_value == 1; }
131
132 [[nodiscard]]
133 friend constexpr bool
134 operator<=(partial_ordering __v, __cmp_cat::__literal_zero) noexcept
135 { return __v._M_reverse() >= 0; }
136
137 [[nodiscard]]
138 friend constexpr bool
139 operator>=(partial_ordering __v, __cmp_cat::__literal_zero) noexcept
140 { return __v._M_value >= 0; }
141
142 [[nodiscard]]
143 friend constexpr bool
144 operator< (__cmp_cat::__literal_zero, partial_ordering __v) noexcept
145 { return __v._M_value == 1; }
146
147 [[nodiscard]]
148 friend constexpr bool
149 operator> (__cmp_cat::__literal_zero, partial_ordering __v) noexcept
150 { return __v._M_value == -1; }
151
152 [[nodiscard]]
153 friend constexpr bool
154 operator<=(__cmp_cat::__literal_zero, partial_ordering __v) noexcept
155 { return 0 <= __v._M_value; }
156
157 [[nodiscard]]
158 friend constexpr bool
159 operator>=(__cmp_cat::__literal_zero, partial_ordering __v) noexcept
160 { return 0 <= __v._M_reverse(); }
161
162 [[nodiscard]]
163 friend constexpr partial_ordering
164 operator<=>(partial_ordering __v, __cmp_cat::__literal_zero) noexcept
165 { return __v; }
166
167 [[nodiscard]]
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())); }
171 };
172
173 // valid values' definitions
174 inline constexpr partial_ordering
175 partial_ordering::less(__cmp_cat::_Ord::less);
176
177 inline constexpr partial_ordering
178 partial_ordering::equivalent(__cmp_cat::_Ord::equivalent);
179
180 inline constexpr partial_ordering
181 partial_ordering::greater(__cmp_cat::_Ord::greater);
182
183 inline constexpr partial_ordering
184 partial_ordering::unordered(__cmp_cat::_Ord::unordered);
185
186 class weak_ordering
187 {
188 __cmp_cat::type _M_value;
189
190 constexpr explicit
191 weak_ordering(__cmp_cat::_Ord __v) noexcept : _M_value(__cmp_cat::type(__v))
192 { }
193
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;
198
199 public:
200 // valid values
201 static const weak_ordering less;
202 static const weak_ordering equivalent;
203 static const weak_ordering greater;
204
205 [[nodiscard]]
206 constexpr operator partial_ordering() const noexcept
207 { return __cmp_cat::__make<partial_ordering>(__cmp_cat::_Ord(_M_value)); }
208
209 // comparisons
210 [[nodiscard]]
211 friend constexpr bool
212 operator==(weak_ordering __v, __cmp_cat::__literal_zero) noexcept
213 { return __v._M_value == 0; }
214
215 [[nodiscard]]
216 friend constexpr bool
217 operator==(weak_ordering, weak_ordering) noexcept = default;
218
219 [[nodiscard]]
220 friend constexpr bool
221 operator< (weak_ordering __v, __cmp_cat::__literal_zero) noexcept
222 { return __v._M_value < 0; }
223
224 [[nodiscard]]
225 friend constexpr bool
226 operator> (weak_ordering __v, __cmp_cat::__literal_zero) noexcept
227 { return __v._M_value > 0; }
228
229 [[nodiscard]]
230 friend constexpr bool
231 operator<=(weak_ordering __v, __cmp_cat::__literal_zero) noexcept
232 { return __v._M_value <= 0; }
233
234 [[nodiscard]]
235 friend constexpr bool
236 operator>=(weak_ordering __v, __cmp_cat::__literal_zero) noexcept
237 { return __v._M_value >= 0; }
238
239 [[nodiscard]]
240 friend constexpr bool
241 operator< (__cmp_cat::__literal_zero, weak_ordering __v) noexcept
242 { return 0 < __v._M_value; }
243
244 [[nodiscard]]
245 friend constexpr bool
246 operator> (__cmp_cat::__literal_zero, weak_ordering __v) noexcept
247 { return 0 > __v._M_value; }
248
249 [[nodiscard]]
250 friend constexpr bool
251 operator<=(__cmp_cat::__literal_zero, weak_ordering __v) noexcept
252 { return 0 <= __v._M_value; }
253
254 [[nodiscard]]
255 friend constexpr bool
256 operator>=(__cmp_cat::__literal_zero, weak_ordering __v) noexcept
257 { return 0 >= __v._M_value; }
258
259 [[nodiscard]]
260 friend constexpr weak_ordering
261 operator<=>(weak_ordering __v, __cmp_cat::__literal_zero) noexcept
262 { return __v; }
263
264 [[nodiscard]]
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)); }
268 };
269
270 // valid values' definitions
271 inline constexpr weak_ordering
272 weak_ordering::less(__cmp_cat::_Ord::less);
273
274 inline constexpr weak_ordering
275 weak_ordering::equivalent(__cmp_cat::_Ord::equivalent);
276
277 inline constexpr weak_ordering
278 weak_ordering::greater(__cmp_cat::_Ord::greater);
279
280 class strong_ordering
281 {
282 __cmp_cat::type _M_value;
283
284 constexpr explicit
285 strong_ordering(__cmp_cat::_Ord __v) noexcept
286 : _M_value(__cmp_cat::type(__v))
287 { }
288
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;
293
294 public:
295 // valid values
296 static const strong_ordering less;
297 static const strong_ordering equal;
298 static const strong_ordering equivalent;
299 static const strong_ordering greater;
300
301 [[nodiscard]]
302 constexpr operator partial_ordering() const noexcept
303 { return __cmp_cat::__make<partial_ordering>(__cmp_cat::_Ord(_M_value)); }
304
305 [[nodiscard]]
306 constexpr operator weak_ordering() const noexcept
307 { return __cmp_cat::__make<weak_ordering>(__cmp_cat::_Ord(_M_value)); }
308
309 // comparisons
310 [[nodiscard]]
311 friend constexpr bool
312 operator==(strong_ordering __v, __cmp_cat::__literal_zero) noexcept
313 { return __v._M_value == 0; }
314
315 [[nodiscard]]
316 friend constexpr bool
317 operator==(strong_ordering, strong_ordering) noexcept = default;
318
319 [[nodiscard]]
320 friend constexpr bool
321 operator< (strong_ordering __v, __cmp_cat::__literal_zero) noexcept
322 { return __v._M_value < 0; }
323
324 [[nodiscard]]
325 friend constexpr bool
326 operator> (strong_ordering __v, __cmp_cat::__literal_zero) noexcept
327 { return __v._M_value > 0; }
328
329 [[nodiscard]]
330 friend constexpr bool
331 operator<=(strong_ordering __v, __cmp_cat::__literal_zero) noexcept
332 { return __v._M_value <= 0; }
333
334 [[nodiscard]]
335 friend constexpr bool
336 operator>=(strong_ordering __v, __cmp_cat::__literal_zero) noexcept
337 { return __v._M_value >= 0; }
338
339 [[nodiscard]]
340 friend constexpr bool
341 operator< (__cmp_cat::__literal_zero, strong_ordering __v) noexcept
342 { return 0 < __v._M_value; }
343
344 [[nodiscard]]
345 friend constexpr bool
346 operator> (__cmp_cat::__literal_zero, strong_ordering __v) noexcept
347 { return 0 > __v._M_value; }
348
349 [[nodiscard]]
350 friend constexpr bool
351 operator<=(__cmp_cat::__literal_zero, strong_ordering __v) noexcept
352 { return 0 <= __v._M_value; }
353
354 [[nodiscard]]
355 friend constexpr bool
356 operator>=(__cmp_cat::__literal_zero, strong_ordering __v) noexcept
357 { return 0 >= __v._M_value; }
358
359 [[nodiscard]]
360 friend constexpr strong_ordering
361 operator<=>(strong_ordering __v, __cmp_cat::__literal_zero) noexcept
362 { return __v; }
363
364 [[nodiscard]]
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)); }
368 };
369
370 // valid values' definitions
371 inline constexpr strong_ordering
372 strong_ordering::less(__cmp_cat::_Ord::less);
373
374 inline constexpr strong_ordering
375 strong_ordering::equal(__cmp_cat::_Ord::equivalent);
376
377 inline constexpr strong_ordering
378 strong_ordering::equivalent(__cmp_cat::_Ord::equivalent);
379
380 inline constexpr strong_ordering
381 strong_ordering::greater(__cmp_cat::_Ord::greater);
382
383
384 // named comparison functions
385 [[nodiscard]]
386 constexpr bool
387 is_eq(partial_ordering __cmp) noexcept
388 { return __cmp == 0; }
389
390 [[nodiscard]]
391 constexpr bool
392 is_neq(partial_ordering __cmp) noexcept
393 { return __cmp != 0; }
394
395 [[nodiscard]]
396 constexpr bool
397 is_lt (partial_ordering __cmp) noexcept
398 { return __cmp < 0; }
399
400 [[nodiscard]]
401 constexpr bool
402 is_lteq(partial_ordering __cmp) noexcept
403 { return __cmp <= 0; }
404
405 [[nodiscard]]
406 constexpr bool
407 is_gt (partial_ordering __cmp) noexcept
408 { return __cmp > 0; }
409
410 [[nodiscard]]
411 constexpr bool
412 is_gteq(partial_ordering __cmp) noexcept
413 { return __cmp >= 0; }
414
415 namespace __detail
416 {
417 template<typename _Tp>
418 inline constexpr unsigned __cmp_cat_id = 1;
419 template<>
420 inline constexpr unsigned __cmp_cat_id<partial_ordering> = 2;
421 template<>
422 inline constexpr unsigned __cmp_cat_id<weak_ordering> = 4;
423 template<>
424 inline constexpr unsigned __cmp_cat_id<strong_ordering> = 8;
425
426 template<typename... _Ts>
427 constexpr auto __common_cmp_cat()
428 {
429 constexpr unsigned __cats = (__cmp_cat_id<_Ts> | ...);
430 // If any Ti is not a comparison category type, U is void.
431 if constexpr (__cats & 1)
432 return;
433 // Otherwise, if at least one Ti is std::partial_ordering,
434 // U is std::partial_ordering.
435 else if constexpr (bool(__cats & __cmp_cat_id<partial_ordering>))
436 return partial_ordering::equivalent;
437 // Otherwise, if at least one Ti is std::weak_ordering,
438 // U is std::weak_ordering.
439 else if constexpr (bool(__cats & __cmp_cat_id<weak_ordering>))
440 return weak_ordering::equivalent;
441 // Otherwise, U is std::strong_ordering.
442 else
443 return strong_ordering::equivalent;
444 }
445 } // namespace __detail
446
447 // [cmp.common], common comparison category type
448 template<typename... _Ts>
449 struct common_comparison_category
450 {
451 using type = decltype(__detail::__common_cmp_cat<_Ts...>());
452 };
453
454 // Partial specializations for one and zero argument cases.
455
456 template<typename _Tp>
457 struct common_comparison_category<_Tp>
458 { using type = void; };
459
460 template<>
461 struct common_comparison_category<partial_ordering>
462 { using type = partial_ordering; };
463
464 template<>
465 struct common_comparison_category<weak_ordering>
466 { using type = weak_ordering; };
467
468 template<>
469 struct common_comparison_category<strong_ordering>
470 { using type = strong_ordering; };
471
472 template<>
473 struct common_comparison_category<>
474 { using type = strong_ordering; };
475
476 template<typename... _Ts>
477 using common_comparison_category_t
478 = typename common_comparison_category<_Ts...>::type;
479
480#if __cpp_lib_three_way_comparison >= 201907L
481 // C++ >= 20 && impl_3way_comparison >= 201907 && lib_concepts
482 namespace __detail
483 {
484 template<typename _Tp, typename _Cat>
485 concept __compares_as
486 = same_as<common_comparison_category_t<_Tp, _Cat>, _Cat>;
487 } // namespace __detail
488
489 // [cmp.concept], concept three_way_comparable
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>
494 && requires(const remove_reference_t<_Tp>& __a,
495 const remove_reference_t<_Tp>& __b)
496 {
497 { __a <=> __b } -> __detail::__compares_as<_Cat>;
498 };
499
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<
508 const remove_reference_t<_Up>&>, _Cat>
509 && __detail::__weakly_eq_cmp_with<_Tp, _Up>
510 && __detail::__partially_ordered_with<_Tp, _Up>
511 && requires(const remove_reference_t<_Tp>& __t,
512 const remove_reference_t<_Up>& __u)
513 {
514 { __t <=> __u } -> __detail::__compares_as<_Cat>;
515 { __u <=> __t } -> __detail::__compares_as<_Cat>;
516 };
517
518 namespace __detail
519 {
520 template<typename _Tp, typename _Up>
521 using __cmp3way_res_t
522 = decltype(std::declval<_Tp>() <=> std::declval<_Up>());
523
524 // Implementation of std::compare_three_way_result.
525 // It is undefined for a program to add specializations of
526 // std::compare_three_way_result, so the std::compare_three_way_result_t
527 // alias ignores std::compare_three_way_result and uses
528 // __detail::__cmp3way_res_impl directly instead.
529 template<typename _Tp, typename _Up>
530 struct __cmp3way_res_impl
531 { };
532
533 template<typename _Tp, typename _Up>
534 requires requires { typename __cmp3way_res_t<__cref<_Tp>, __cref<_Up>>; }
535 struct __cmp3way_res_impl<_Tp, _Up>
536 {
537 using type = __cmp3way_res_t<__cref<_Tp>, __cref<_Up>>;
538 };
539 } // namespace __detail
540
541 /// [cmp.result], result of three-way comparison
542 template<typename _Tp, typename _Up = _Tp>
544 : __detail::__cmp3way_res_impl<_Tp, _Up>
545 { };
546
547 /// [cmp.result], result of three-way comparison
548 template<typename _Tp, typename _Up = _Tp>
550 = typename __detail::__cmp3way_res_impl<_Tp, _Up>::type;
551
552 namespace __detail
553 {
554 // BUILTIN-PTR-THREE-WAY(T, U)
555 // This determines whether t <=> u results in a call to a built-in
556 // operator<=> comparing pointers. It doesn't work for function pointers
557 // (PR 93628).
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)); };
568 } // namespace __detail
569
570 // _GLIBCXX_RESOLVE_LIB_DEFECTS
571 // 3530 BUILTIN-PTR-MEOW should not opt the type out of syntactic checks
572
573 // [cmp.object], typename compare_three_way
574 struct compare_three_way
575 {
576#pragma GCC diagnostic push
577#pragma GCC diagnostic ignored "-Wc++23-extensions" // static operator()
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)
582 noexcept(noexcept(std::declval<_Tp>() <=> std::declval<_Up>()))
583 {
584 if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>)
585 {
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;
593 }
594 else
595 return static_cast<_Tp&&>(__t) <=> static_cast<_Up&&>(__u);
596 }
597#pragma GCC diagnostic pop
598
599 using is_transparent = void;
600 };
601
602 /// @cond undocumented
603 // Namespace for helpers for the <compare> customization points.
604 namespace __compare
605 {
606 template<floating_point _Tp>
607 constexpr weak_ordering
608 __fp_weak_ordering(_Tp __e, _Tp __f)
609 {
610 auto __po = __cmp_cat::__ord(__e <=> __f);
611 if (__po != __cmp_cat::_Ord::unordered)
612 return __cmp_cat::__make<weak_ordering>(__po);
613 else // unordered, at least one argument is NaN
614 {
615 // return -1 for negative nan, +1 for positive nan, 0 otherwise.
616 auto __isnan_sign = [](_Tp __fp) -> int {
617 return __builtin_isnan(__fp)
618 ? __builtin_signbit(__fp) ? -1 : 1
619 : 0;
620 };
621 return __isnan_sign(__e) <=> __isnan_sign(__f);
622 }
623 }
624
625 void strong_order() = delete;
626
627 template<typename _Tp, typename _Up>
628 concept __adl_strong = requires(_Tp&& __t, _Up&& __u)
629 {
630 strong_ordering(strong_order(static_cast<_Tp&&>(__t),
631 static_cast<_Up&&>(__u)));
632 };
633
634 void weak_order() = delete;
635
636 template<typename _Tp, typename _Up>
637 concept __adl_weak = requires(_Tp&& __t, _Up&& __u)
638 {
639 weak_ordering(weak_order(static_cast<_Tp&&>(__t),
640 static_cast<_Up&&>(__u)));
641 };
642
643 void partial_order() = delete;
644
645 template<typename _Tp, typename _Up>
646 concept __adl_partial = requires(_Tp&& __t, _Up&& __u)
647 {
648 partial_ordering(partial_order(static_cast<_Tp&&>(__t),
649 static_cast<_Up&&>(__u)));
650 };
651
652 template<typename _Ord, typename _Tp, typename _Up>
653 concept __cmp3way = requires(_Tp&& __t, _Up&& __u, compare_three_way __c)
654 {
655 _Ord(__c(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)));
656 };
657
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>;
663
664 template<typename _Tp, typename _Up>
665 concept __decayed_same_as = same_as<decay_t<_Tp>, decay_t<_Up>>;
666
667 class _Strong_order
668 {
669 template<typename _Tp, typename _Up>
670 static constexpr bool
671 _S_noexcept()
672 {
673 if constexpr (floating_point<decay_t<_Tp>>)
674 return true;
675 else if constexpr (__adl_strong<_Tp, _Up>)
676 return noexcept(strong_ordering(strong_order(std::declval<_Tp>(),
678 else if constexpr (__cmp3way<strong_ordering, _Tp, _Up>)
679 return noexcept(compare_three_way()(std::declval<_Tp>(),
681 }
682
683 friend class _Weak_order;
684 friend class _Strong_fallback;
685
686 // Names for the supported floating-point representations.
687 enum class _Fp_fmt
688 {
689 _Binary16, _Binary32, _Binary64, _Binary128, // IEEE
690 _X86_80bit, // x86 80-bit extended precision
691 _M68k_80bit, // m68k 80-bit extended precision
692 _Dbldbl, // IBM 128-bit double-double
693 _Bfloat16, // std::bfloat16_t
694 };
695
696#ifndef __cpp_using_enum
697 // XXX Remove these once 'using enum' support is ubiquitous.
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;
706#endif
707
708 // Identify the format used by a floating-point type.
709 template<typename _Tp>
710 static consteval _Fp_fmt
711 _S_fp_fmt() noexcept
712 {
713#ifdef __cpp_using_enum
714 using enum _Fp_fmt;
715#endif
716
717 // Identify these formats first, then assume anything else is IEEE.
718 // N.B. ARM __fp16 alternative format can be handled as binary16.
719
720#ifdef __LONG_DOUBLE_IBM128__
721 if constexpr (__is_same(_Tp, long double))
722 return _Dbldbl;
723#elif defined __LONG_DOUBLE_IEEE128__ && defined __SIZEOF_IBM128__
724 if constexpr (__is_same(_Tp, __ibm128))
725 return _Dbldbl;
726#endif
727
728#if __LDBL_MANT_DIG__ == 64
729 if constexpr (__is_same(_Tp, long double))
730 return __LDBL_MIN_EXP__ == -16381 ? _X86_80bit : _M68k_80bit;
731#endif
732#ifdef __SIZEOF_FLOAT80__
733 if constexpr (__is_same(_Tp, __float80))
734 return _X86_80bit;
735#endif
736#ifdef __STDCPP_BFLOAT16_T__
737 if constexpr (__is_same(_Tp, decltype(0.0bf16)))
738 return _Bfloat16;
739#endif
740
741 constexpr int __width = sizeof(_Tp) * __CHAR_BIT__;
742
743 if constexpr (__width == 16) // IEEE binary16 (or ARM fp16).
744 return _Binary16;
745 else if constexpr (__width == 32) // IEEE binary32
746 return _Binary32;
747 else if constexpr (__width == 64) // IEEE binary64
748 return _Binary64;
749 else if constexpr (__width == 128) // IEEE binary128
750 return _Binary128;
751 }
752
753 // So we don't need to include <stdint.h> and pollute the namespace.
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__;
759
760 // Used to unpack floating-point types that do not fit into an integer.
761 template<typename _Tp>
762 struct _Int
763 {
764#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
765 uint64_t _M_lo;
766 _Tp _M_hi;
767#else
768 _Tp _M_hi;
769 uint64_t _M_lo;
770#endif
771
772 constexpr explicit
773 _Int(_Tp __hi, uint64_t __lo) noexcept : _M_hi(__hi)
774 { _M_lo = __lo; }
775
776 constexpr explicit
777 _Int(uint64_t __lo) noexcept : _M_hi(0)
778 { _M_lo = __lo; }
779
780 constexpr bool operator==(const _Int&) const = default;
781
782#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
783 consteval _Int
784 operator<<(int __n) const noexcept
785 {
786 // XXX this assumes n >= 64, which is true for the use below.
787 return _Int(static_cast<_Tp>(_M_lo << (__n - 64)), 0);
788 }
789#endif
790
791 constexpr _Int&
792 operator^=(const _Int& __rhs) noexcept
793 {
794 _M_hi ^= __rhs._M_hi;
795 _M_lo ^= __rhs._M_lo;
796 return *this;
797 }
798
799 constexpr strong_ordering
800 operator<=>(const _Int& __rhs) const noexcept
801 {
802 strong_ordering __cmp = _M_hi <=> __rhs._M_hi;
803 if (__cmp != strong_ordering::equal)
804 return __cmp;
805 return _M_lo <=> __rhs._M_lo;
806 }
807 };
808
809 template<typename _Tp>
810 static constexpr _Tp
811 _S_compl(_Tp __t) noexcept
812 {
813 constexpr int __width = sizeof(_Tp) * __CHAR_BIT__;
814 // Sign extend to get all ones or all zeros.
815 make_unsigned_t<_Tp> __sign = __t >> (__width - 1);
816 // If the sign bit was set, this flips all bits below it.
817 // This converts ones' complement to two's complement.
818 return __t ^ (__sign >> 1);
819 }
820
821 // As above but works on both parts of _Int<T>.
822 template<typename _Tp>
823 static constexpr _Int<_Tp>
824 _S_compl(_Int<_Tp> __t) noexcept
825 {
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;
831 return __t;
832 }
833
834 // Bit-cast a floating-point value to an unsigned integer.
835 template<typename _Tp>
836 constexpr static auto
837 _S_fp_bits(_Tp __val) noexcept
838 {
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);
845 else
846 {
847#ifdef __cpp_using_enum
848 using enum _Fp_fmt;
849#endif
850 constexpr auto __fmt = _S_fp_fmt<_Tp>();
851 if constexpr (__fmt == _X86_80bit)
852 {
853 if constexpr (sizeof(_Tp) == 3 * sizeof(int32_t))
854 {
855 auto __ival = __builtin_bit_cast(_Int<int32_t>, __val);
856 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
857 }
858 else
859 {
860 auto __ival = __builtin_bit_cast(_Int<int64_t>, __val);
861 return _Int<int16_t>(__ival._M_hi, __ival._M_lo);
862 }
863 }
864 else if constexpr (__fmt == _M68k_80bit)
865 {
866 auto __ival = __builtin_bit_cast(_Int<int32_t>, __val);
867 return _Int<int16_t>(__ival._M_hi >> 16, __ival._M_lo);
868 }
869 else if constexpr (sizeof(_Tp) == 2 * sizeof(int64_t))
870 {
871#if __SIZEOF_INT128__
872 return __builtin_bit_cast(__int128, __val);
873#else
874 return __builtin_bit_cast(_Int<int64_t>, __val);
875#endif
876 }
877 else
878 static_assert(sizeof(_Tp) == sizeof(int64_t),
879 "unsupported floating-point type");
880 }
881 }
882
883 template<typename _Tp>
884 static constexpr strong_ordering
885 _S_fp_cmp(_Tp __x, _Tp __y) noexcept
886 {
887#ifdef __vax__
888 if (__builtin_isnan(__x) || __builtin_isnan(__y))
889 {
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;
895 }
896 else
897 return __builtin_bit_cast(strong_ordering, __x <=> __y);
898#endif
899
900 auto __ix = _S_fp_bits(__x);
901 auto __iy = _S_fp_bits(__y);
902
903 if (__ix == __iy)
904 return strong_ordering::equal; // All bits are equal, we're done.
905
906#ifdef __cpp_using_enum
907 using enum _Fp_fmt;
908#endif
909 constexpr auto __fmt = _S_fp_fmt<_Tp>();
910
911 if constexpr (__fmt == _Dbldbl) // double-double
912 {
913 // Unpack the double-double into two parts.
914 // We never inspect the low double as a double, cast to integer.
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);
918
919 // Compare the high doubles first and use result if unequal.
920 auto __cmp = _S_fp_cmp(__x2._M_hi, __y2._M_hi);
921 if (__cmp != strong_ordering::equal)
922 return __cmp;
923
924 // For NaN the low double is unused, so if the high doubles
925 // are the same NaN, we don't need to compare the low doubles.
926 if (__builtin_isnan(__x2._M_hi))
927 return strong_ordering::equal;
928 // Similarly, if the low doubles are +zero or -zero (which is
929 // true for all infinities and some other values), we're done.
930 if (((__x2._M_lo | __y2._M_lo) & 0x7fffffffffffffffULL) == 0)
931 return strong_ordering::equal;
932
933 // Otherwise, compare the low parts.
934 return _S_compl(__x2._M_lo) <=> _S_compl(__y2._M_lo);
935 }
936 else
937 {
938 if constexpr (__fmt == _M68k_80bit)
939 {
940 // For m68k the MSB of the significand is ignored for the
941 // greatest exponent, so either 0 or 1 is valid there.
942 // Set it before comparing, so that we never have 0 there.
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;
948 }
949 else
950 {
951#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
952 // IEEE 754-1985 allowed the meaning of the quiet/signaling
953 // bit to be reversed. Flip that to give desired ordering.
954 if (__builtin_isnan(__x) && __builtin_isnan(__y))
955 {
956 using _Int = decltype(__ix);
957
958 constexpr int __nantype = __fmt == _Binary32 ? 22
959 : __fmt == _Binary64 ? 51
960 : __fmt == _Binary128 ? 111
961 : -1;
962 constexpr _Int __bit = _Int(1) << __nantype;
963 __ix ^= __bit;
964 __iy ^= __bit;
965 }
966#endif
967 }
968 return _S_compl(__ix) <=> _S_compl(__iy);
969 }
970 }
971
972 public:
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>())
978 {
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));
987 }
988 };
989
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>;
996
997 class _Weak_order
998 {
999 template<typename _Tp, typename _Up>
1000 static constexpr bool
1001 _S_noexcept()
1002 {
1003 if constexpr (floating_point<decay_t<_Tp>>)
1004 return true;
1005 else if constexpr (__adl_weak<_Tp, _Up>)
1006 return noexcept(weak_ordering(weak_order(std::declval<_Tp>(),
1007 std::declval<_Up>())));
1008 else if constexpr (__cmp3way<weak_ordering, _Tp, _Up>)
1009 return noexcept(compare_three_way()(std::declval<_Tp>(),
1011 else if constexpr (__strongly_ordered<_Tp, _Up>)
1012 return _Strong_order::_S_noexcept<_Tp, _Up>();
1013 }
1014
1015 friend class _Partial_order;
1016 friend class _Weak_fallback;
1017
1018 public:
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>())
1024 {
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));
1036 }
1037 };
1038
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>;
1044
1045 class _Partial_order
1046 {
1047 template<typename _Tp, typename _Up>
1048 static constexpr bool
1049 _S_noexcept()
1050 {
1051 if constexpr (__adl_partial<_Tp, _Up>)
1052 return noexcept(partial_ordering(partial_order(std::declval<_Tp>(),
1053 std::declval<_Up>())));
1054 else if constexpr (__cmp3way<partial_ordering, _Tp, _Up>)
1055 return noexcept(compare_three_way()(std::declval<_Tp>(),
1057 else if constexpr (__weakly_ordered<_Tp, _Up>)
1058 return _Weak_order::_S_noexcept<_Tp, _Up>();
1059 }
1060
1061 friend class _Partial_fallback;
1062
1063 public:
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>())
1069 {
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));
1079 }
1080 };
1081
1082 template<typename _Tp, typename _Up>
1083 concept __op_eq_lt = requires(_Tp&& __t, _Up&& __u)
1084 {
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>;
1089 };
1090
1091 class _Strong_fallback
1092 {
1093 template<typename _Tp, typename _Up>
1094 static constexpr bool
1095 _S_noexcept()
1096 {
1097 if constexpr (__strongly_ordered<_Tp, _Up>)
1098 return _Strong_order::_S_noexcept<_Tp, _Up>();
1099 else
1100 return noexcept(bool(std::declval<_Tp>() == std::declval<_Up>()))
1101 && noexcept(bool(std::declval<_Tp>() < std::declval<_Up>()));
1102 }
1103
1104 public:
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>())
1110 {
1111 if constexpr (__strongly_ordered<_Tp, _Up>)
1112 return _Strong_order{}(static_cast<_Tp&&>(__e),
1113 static_cast<_Up&&>(__f));
1114 else // __op_eq_lt<_Tp, _Up>
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;
1120 }
1121 };
1122
1123 class _Weak_fallback
1124 {
1125 template<typename _Tp, typename _Up>
1126 static constexpr bool
1127 _S_noexcept()
1128 {
1129 if constexpr (__weakly_ordered<_Tp, _Up>)
1130 return _Weak_order::_S_noexcept<_Tp, _Up>();
1131 else
1132 return noexcept(bool(std::declval<_Tp>() == std::declval<_Up>()))
1133 && noexcept(bool(std::declval<_Tp>() < std::declval<_Up>()));
1134 }
1135
1136 public:
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>())
1142 {
1143 if constexpr (__weakly_ordered<_Tp, _Up>)
1144 return _Weak_order{}(static_cast<_Tp&&>(__e),
1145 static_cast<_Up&&>(__f));
1146 else // __op_eq_lt<_Tp, _Up>
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;
1152 }
1153 };
1154
1155 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1156 // 3465. compare_partial_order_fallback requires F < E
1157 template<typename _Tp, typename _Up>
1158 concept __op_eq_lt_lt = __op_eq_lt<_Tp, _Up>
1159 && requires(_Tp&& __t, _Up&& __u)
1160 {
1161 { static_cast<_Up&&>(__u) < static_cast<_Tp&&>(__t) }
1162 -> convertible_to<bool>;
1163 };
1164
1165 class _Partial_fallback
1166 {
1167 template<typename _Tp, typename _Up>
1168 static constexpr bool
1169 _S_noexcept()
1170 {
1171 if constexpr (__partially_ordered<_Tp, _Up>)
1172 return _Partial_order::_S_noexcept<_Tp, _Up>();
1173 else
1174 return noexcept(bool(std::declval<_Tp>() == std::declval<_Up>()))
1175 && noexcept(bool(std::declval<_Tp>() < std::declval<_Up>()));
1176 }
1177
1178 public:
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>())
1184 {
1185 if constexpr (__partially_ordered<_Tp, _Up>)
1186 return _Partial_order{}(static_cast<_Tp&&>(__e),
1187 static_cast<_Up&&>(__f));
1188 else // __op_eq_lt_lt<_Tp, _Up>
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;
1196 }
1197 };
1198 } // namespace @endcond
1199
1200 // [cmp.alg], comparison algorithms
1201
1202 inline namespace _Cpo
1203 {
1204 inline constexpr __compare::_Strong_order strong_order{};
1205
1206 inline constexpr __compare::_Weak_order weak_order{};
1207
1208 inline constexpr __compare::_Partial_order partial_order{};
1209
1210 inline constexpr __compare::_Strong_fallback
1211 compare_strong_order_fallback{};
1212
1213 inline constexpr __compare::_Weak_fallback
1214 compare_weak_order_fallback{};
1215
1216 inline constexpr __compare::_Partial_fallback
1217 compare_partial_order_fallback{};
1218 }
1219
1220 /// @cond undocumented
1221 namespace __detail
1222 {
1223 // [expos.only.func] synth-three-way
1224 inline constexpr struct _Synth3way
1225 {
1226 template<typename _Tp, typename _Up>
1227 static constexpr bool
1228 _S_noexcept(const _Tp* __t = nullptr, const _Up* __u = nullptr)
1229 {
1230 if constexpr (three_way_comparable_with<_Tp, _Up>)
1231 return noexcept(*__t <=> *__u);
1232 else
1233 return noexcept(*__t < *__u) && noexcept(*__u < *__t);
1234 }
1235
1236 template<typename _Tp, typename _Up>
1237 [[nodiscard]]
1238 constexpr auto
1239 operator()(const _Tp& __t, const _Up& __u) const
1240 noexcept(_S_noexcept<_Tp, _Up>())
1241 requires requires
1242 {
1243 { __t < __u } -> __boolean_testable;
1244 { __u < __t } -> __boolean_testable;
1245 }
1246 {
1247 if constexpr (three_way_comparable_with<_Tp, _Up>)
1248 return __t <=> __u;
1249 else
1250 {
1251 if (__t < __u)
1252 return weak_ordering::less;
1253 else if (__u < __t)
1254 return weak_ordering::greater;
1255 else
1256 return weak_ordering::equivalent;
1257 }
1258 }
1259 } __synth3way = {};
1260
1261 // [expos.only.func] synth-three-way-result
1262 template<typename _Tp, typename _Up = _Tp>
1263 using __synth3way_t
1264 = decltype(__detail::__synth3way(std::declval<_Tp&>(),
1266 } // namespace __detail
1267 /// @endcond
1268
1269#if __glibcxx_type_order >= 202506L // C++ >= 26
1270 /// Total ordering of types.
1271 /// @since C++26
1272
1273 template<typename _Tp, typename _Up>
1274 struct type_order
1275 {
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; }
1280 };
1281
1282 /// @ingroup variable_templates
1283 /// @since C++26
1284 template<typename _Tp, typename _Up>
1285 inline constexpr strong_ordering type_order_v
1286 = __builtin_type_order(_Tp, _Up);
1287#endif // __glibcxx_type_order >= 202506L
1288
1289#endif // __cpp_lib_three_way_comparison >= 201907L
1290} // namespace std
1291
1292#pragma GCC diagnostic pop
1293
1294#endif // C++20
1295
1296#endif // _COMPARE
typename common_reference< _Tp... >::type common_reference_t
Definition type_traits:4213
typename remove_reference< _Tp >::type remove_reference_t
Alias template for remove_reference.
Definition type_traits:1844
auto declval() noexcept -> decltype(__declval< _Tp >(0))
Definition type_traits:2672
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
Definition compare:548
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition bitset:1740
Implementation details not part of the namespace std interface.
[cmp.result], result of three-way comparison
Definition compare:544