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