Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcompare.h
Go to the documentation of this file.
1// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2// Copyright (C) 2023 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QCOMPARE_H
6#define QCOMPARE_H
7
8#if 0
9#pragma qt_class(QtCompare)
10#endif
11
12#include <QtCore/qglobal.h>
13#include <QtCore/qcompare_impl.h>
14
15#ifdef __cpp_lib_bit_cast
16#include <bit>
17#endif
18#ifdef __cpp_lib_three_way_comparison
19#include <compare>
20#endif
21
22QT_BEGIN_NAMESPACE
23
24namespace QtPrivate {
26
27// [cmp.categories.pre] / 1
29{
30 Equal = 0,
32 Less = -1,
33 Greater = 1
34};
35
37{
38 Unordered =
39 #if defined(_LIBCPP_VERSION) // libc++
40 -127
41 #elif defined(__GLIBCXX__) // libstdc++
42 2
43 #elif defined(_MSVC_STL_VERSION) // MS-STL
44 -128
45 #elif defined(Q_CC_GHS) // INTEGRITY does not have a C++20 stdlib,
46 // but is going to use libc++ in the future,
47 // so stay compatible for now.
48 -127
49 #elif defined(Q_OS_VXWORKS) // VxWorks does not have a C++20 stdlib,
50 // so we wont't promise BC there.
51 2
52 #else
53 # error "Unsupported C++ Standard Library implementation. Please submit a bug report."
54 #endif
55};
56
57} // namespace QtPrivate
58
60
61template <typename O>
62constexpr O reversed(O o) noexcept
63{
64 // https://eel.is/c++draft/cmp.partialord#5
65 return is_lt(o) ? O::greater :
66 is_gt(o) ? O::less :
67 /*else*/ o ;
68}
69
70} // namespace QtOrderingPrivate
71
72namespace Qt {
73
74class weak_ordering;
75class strong_ordering;
76
78{
79public:
80 static const partial_ordering less;
84
85 friend constexpr bool operator==(partial_ordering lhs,
87 { return lhs.isOrdered() && lhs.m_order == 0; }
88
89 friend constexpr bool operator!=(partial_ordering lhs,
91 { return !lhs.isOrdered() || lhs.m_order != 0; }
92
93 friend constexpr bool operator< (partial_ordering lhs,
95 { return lhs.isOrdered() && lhs.m_order < 0; }
96
97 friend constexpr bool operator<=(partial_ordering lhs,
99 { return lhs.isOrdered() && lhs.m_order <= 0; }
100
101 friend constexpr bool operator> (partial_ordering lhs,
103 { return lhs.isOrdered() && lhs.m_order > 0; }
104
105 friend constexpr bool operator>=(partial_ordering lhs,
107 { return lhs.isOrdered() && lhs.m_order >= 0; }
108
109
111 partial_ordering rhs) noexcept
112 { return rhs.isOrdered() && 0 == rhs.m_order; }
113
115 partial_ordering rhs) noexcept
116 { return !rhs.isOrdered() || 0 != rhs.m_order; }
117
119 partial_ordering rhs) noexcept
120 { return rhs.isOrdered() && 0 < rhs.m_order; }
121
123 partial_ordering rhs) noexcept
124 { return rhs.isOrdered() && 0 <= rhs.m_order; }
125
127 partial_ordering rhs) noexcept
128 { return rhs.isOrdered() && 0 > rhs.m_order; }
129
131 partial_ordering rhs) noexcept
132 { return rhs.isOrdered() && 0 >= rhs.m_order; }
133
134
135#ifdef __cpp_lib_three_way_comparison
136 friend constexpr std::partial_ordering
138 { return lhs; } // https://eel.is/c++draft/cmp.partialord#4
139
140 friend constexpr std::partial_ordering
142 { return QtOrderingPrivate::reversed(rhs); }
143#endif // __cpp_lib_three_way_comparison
144
145
146 friend constexpr bool operator==(partial_ordering lhs, partial_ordering rhs) noexcept
147 { return lhs.m_order == rhs.m_order; }
148
149 friend constexpr bool operator!=(partial_ordering lhs, partial_ordering rhs) noexcept
150 { return lhs.m_order != rhs.m_order; }
151
152#ifdef __cpp_lib_three_way_comparison
154 {
159 else if (stdorder == std::partial_ordering::greater)
163 }
164
165 constexpr Q_IMPLICIT operator std::partial_ordering() const noexcept
166 {
167 static_assert(sizeof(*this) == sizeof(std::partial_ordering));
168#ifdef __cpp_lib_bit_cast
169 return std::bit_cast<std::partial_ordering>(*this);
170#else
171 using O = QtPrivate::Ordering;
172 using U = QtPrivate::Uncomparable;
173 using R = std::partial_ordering;
174 switch (m_order) {
175 case qToUnderlying(O::Less): return R::less;
176 case qToUnderlying(O::Greater): return R::greater;
177 case qToUnderlying(O::Equivalent): return R::equivalent;
178 case qToUnderlying(U::Unordered): return R::unordered;
179 }
181#endif // __cpp_lib_bit_cast
182 }
183
184 friend constexpr bool operator==(partial_ordering lhs, std::partial_ordering rhs) noexcept
185 { return static_cast<std::partial_ordering>(lhs) == rhs; }
186
187 friend constexpr bool operator!=(partial_ordering lhs, std::partial_ordering rhs) noexcept
188 { return static_cast<std::partial_ordering>(lhs) != rhs; }
189
190 friend constexpr bool operator==(std::partial_ordering lhs, partial_ordering rhs) noexcept
191 { return lhs == static_cast<std::partial_ordering>(rhs); }
192
193 friend constexpr bool operator!=(std::partial_ordering lhs, partial_ordering rhs) noexcept
194 { return lhs != static_cast<std::partial_ordering>(rhs); }
195
196 friend constexpr bool operator==(partial_ordering lhs, std::strong_ordering rhs) noexcept
197 { return static_cast<std::partial_ordering>(lhs) == rhs; }
198
199 friend constexpr bool operator!=(partial_ordering lhs, std::strong_ordering rhs) noexcept
200 { return static_cast<std::partial_ordering>(lhs) != rhs; }
201
202 friend constexpr bool operator==(std::strong_ordering lhs, partial_ordering rhs) noexcept
203 { return lhs == static_cast<std::partial_ordering>(rhs); }
204
205 friend constexpr bool operator!=(std::strong_ordering lhs, partial_ordering rhs) noexcept
206 { return lhs != static_cast<std::partial_ordering>(rhs); }
207
208 friend constexpr bool operator==(partial_ordering lhs, std::weak_ordering rhs) noexcept
209 { return static_cast<std::partial_ordering>(lhs) == rhs; }
210
211 friend constexpr bool operator!=(partial_ordering lhs, std::weak_ordering rhs) noexcept
212 { return static_cast<std::partial_ordering>(lhs) != rhs; }
213
214 friend constexpr bool operator==(std::weak_ordering lhs, partial_ordering rhs) noexcept
215 { return lhs == static_cast<std::partial_ordering>(rhs); }
216
217 friend constexpr bool operator!=(std::weak_ordering lhs, partial_ordering rhs) noexcept
218 { return lhs != static_cast<std::partial_ordering>(rhs); }
219#endif // __cpp_lib_three_way_comparison
220
221private:
222 friend class weak_ordering;
223 friend class strong_ordering;
224
225 constexpr explicit partial_ordering(QtPrivate::Ordering order) noexcept
226 : m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
227 {}
228 constexpr explicit partial_ordering(QtPrivate::Uncomparable order) noexcept
229 : m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
230 {}
231
232 QT_WARNING_PUSH
233 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903
234 QT_WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant")
235 friend constexpr bool is_eq (partial_ordering o) noexcept { return o == 0; }
236 friend constexpr bool is_neq (partial_ordering o) noexcept { return o != 0; }
237 friend constexpr bool is_lt (partial_ordering o) noexcept { return o < 0; }
238 friend constexpr bool is_lteq(partial_ordering o) noexcept { return o <= 0; }
239 friend constexpr bool is_gt (partial_ordering o) noexcept { return o > 0; }
240 friend constexpr bool is_gteq(partial_ordering o) noexcept { return o >= 0; }
242
243 // instead of the exposition only is_ordered member in [cmp.partialord],
244 // use a private function
245 constexpr bool isOrdered() const noexcept
247
249};
250
255
257{
258public:
259 static const weak_ordering less;
261 static const weak_ordering greater;
262
263 constexpr Q_IMPLICIT operator partial_ordering() const noexcept
264 { return partial_ordering(static_cast<QtPrivate::Ordering>(m_order)); }
265
266 friend constexpr bool operator==(weak_ordering lhs,
268 { return lhs.m_order == 0; }
269
270 friend constexpr bool operator!=(weak_ordering lhs,
272 { return lhs.m_order != 0; }
273
274 friend constexpr bool operator< (weak_ordering lhs,
276 { return lhs.m_order < 0; }
277
278 friend constexpr bool operator<=(weak_ordering lhs,
280 { return lhs.m_order <= 0; }
281
282 friend constexpr bool operator> (weak_ordering lhs,
284 { return lhs.m_order > 0; }
285
286 friend constexpr bool operator>=(weak_ordering lhs,
288 { return lhs.m_order >= 0; }
289
290
292 weak_ordering rhs) noexcept
293 { return 0 == rhs.m_order; }
294
296 weak_ordering rhs) noexcept
297 { return 0 != rhs.m_order; }
298
300 weak_ordering rhs) noexcept
301 { return 0 < rhs.m_order; }
302
304 weak_ordering rhs) noexcept
305 { return 0 <= rhs.m_order; }
306
308 weak_ordering rhs) noexcept
309 { return 0 > rhs.m_order; }
310
312 weak_ordering rhs) noexcept
313 { return 0 >= rhs.m_order; }
314
315
316#ifdef __cpp_lib_three_way_comparison
317 friend constexpr std::weak_ordering
319 { return lhs; } // https://eel.is/c++draft/cmp.weakord#5
320
321 friend constexpr std::weak_ordering
323 { return QtOrderingPrivate::reversed(rhs); }
324#endif // __cpp_lib_three_way_comparison
325
326
327 friend constexpr bool operator==(weak_ordering lhs, weak_ordering rhs) noexcept
328 { return lhs.m_order == rhs.m_order; }
329
330 friend constexpr bool operator!=(weak_ordering lhs, weak_ordering rhs) noexcept
331 { return lhs.m_order != rhs.m_order; }
332
333 friend constexpr bool operator==(weak_ordering lhs, partial_ordering rhs) noexcept
334 { return static_cast<partial_ordering>(lhs) == rhs; }
335
336 friend constexpr bool operator!=(weak_ordering lhs, partial_ordering rhs) noexcept
337 { return static_cast<partial_ordering>(lhs) != rhs; }
338
339 friend constexpr bool operator==(partial_ordering lhs, weak_ordering rhs) noexcept
340 { return lhs == static_cast<partial_ordering>(rhs); }
341
342 friend constexpr bool operator!=(partial_ordering lhs, weak_ordering rhs) noexcept
343 { return lhs != static_cast<partial_ordering>(rhs); }
344
345#ifdef __cpp_lib_three_way_comparison
347 {
350 else if (stdorder == std::weak_ordering::equivalent)
352 else if (stdorder == std::weak_ordering::greater)
354 }
355
356 constexpr Q_IMPLICIT operator std::weak_ordering() const noexcept
357 {
358 static_assert(sizeof(*this) == sizeof(std::weak_ordering));
359#ifdef __cpp_lib_bit_cast
360 return std::bit_cast<std::weak_ordering>(*this);
361#else
362 using O = QtPrivate::Ordering;
363 using R = std::weak_ordering;
364 switch (m_order) {
365 case qToUnderlying(O::Less): return R::less;
366 case qToUnderlying(O::Greater): return R::greater;
367 case qToUnderlying(O::Equivalent): return R::equivalent;
368 }
370#endif // __cpp_lib_bit_cast
371 }
372
373 friend constexpr bool operator==(weak_ordering lhs, std::weak_ordering rhs) noexcept
374 { return static_cast<std::weak_ordering>(lhs) == rhs; }
375
376 friend constexpr bool operator!=(weak_ordering lhs, std::weak_ordering rhs) noexcept
377 { return static_cast<std::weak_ordering>(lhs) != rhs; }
378
379 friend constexpr bool operator==(weak_ordering lhs, std::partial_ordering rhs) noexcept
380 { return static_cast<std::weak_ordering>(lhs) == rhs; }
381
382 friend constexpr bool operator!=(weak_ordering lhs, std::partial_ordering rhs) noexcept
383 { return static_cast<std::weak_ordering>(lhs) != rhs; }
384
385 friend constexpr bool operator==(weak_ordering lhs, std::strong_ordering rhs) noexcept
386 { return static_cast<std::weak_ordering>(lhs) == rhs; }
387
388 friend constexpr bool operator!=(weak_ordering lhs, std::strong_ordering rhs) noexcept
389 { return static_cast<std::weak_ordering>(lhs) != rhs; }
390
391 friend constexpr bool operator==(std::weak_ordering lhs, weak_ordering rhs) noexcept
392 { return lhs == static_cast<std::weak_ordering>(rhs); }
393
394 friend constexpr bool operator!=(std::weak_ordering lhs, weak_ordering rhs) noexcept
395 { return lhs != static_cast<std::weak_ordering>(rhs); }
396
397 friend constexpr bool operator==(std::partial_ordering lhs, weak_ordering rhs) noexcept
398 { return lhs == static_cast<std::weak_ordering>(rhs); }
399
400 friend constexpr bool operator!=(std::partial_ordering lhs, weak_ordering rhs) noexcept
401 { return lhs != static_cast<std::weak_ordering>(rhs); }
402
403 friend constexpr bool operator==(std::strong_ordering lhs, weak_ordering rhs) noexcept
404 { return lhs == static_cast<std::weak_ordering>(rhs); }
405
406 friend constexpr bool operator!=(std::strong_ordering lhs, weak_ordering rhs) noexcept
407 { return lhs != static_cast<std::weak_ordering>(rhs); }
408#endif // __cpp_lib_three_way_comparison
409
410private:
411 friend class strong_ordering;
412
413 constexpr explicit weak_ordering(QtPrivate::Ordering order) noexcept
414 : m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
415 {}
416
417 QT_WARNING_PUSH
418 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903
419 QT_WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant")
420 friend constexpr bool is_eq (weak_ordering o) noexcept { return o == 0; }
421 friend constexpr bool is_neq (weak_ordering o) noexcept { return o != 0; }
422 friend constexpr bool is_lt (weak_ordering o) noexcept { return o < 0; }
423 friend constexpr bool is_lteq(weak_ordering o) noexcept { return o <= 0; }
424 friend constexpr bool is_gt (weak_ordering o) noexcept { return o > 0; }
425 friend constexpr bool is_gteq(weak_ordering o) noexcept { return o >= 0; }
427
429};
430
434
436{
437public:
438 static const strong_ordering less;
440 static const strong_ordering equal;
442
443 constexpr Q_IMPLICIT operator partial_ordering() const noexcept
444 { return partial_ordering(static_cast<QtPrivate::Ordering>(m_order)); }
445
446 constexpr Q_IMPLICIT operator weak_ordering() const noexcept
447 { return weak_ordering(static_cast<QtPrivate::Ordering>(m_order)); }
448
449 friend constexpr bool operator==(strong_ordering lhs,
451 { return lhs.m_order == 0; }
452
453 friend constexpr bool operator!=(strong_ordering lhs,
455 { return lhs.m_order != 0; }
456
457 friend constexpr bool operator< (strong_ordering lhs,
459 { return lhs.m_order < 0; }
460
461 friend constexpr bool operator<=(strong_ordering lhs,
463 { return lhs.m_order <= 0; }
464
465 friend constexpr bool operator> (strong_ordering lhs,
467 { return lhs.m_order > 0; }
468
469 friend constexpr bool operator>=(strong_ordering lhs,
471 { return lhs.m_order >= 0; }
472
473
475 strong_ordering rhs) noexcept
476 { return 0 == rhs.m_order; }
477
479 strong_ordering rhs) noexcept
480 { return 0 != rhs.m_order; }
481
483 strong_ordering rhs) noexcept
484 { return 0 < rhs.m_order; }
485
487 strong_ordering rhs) noexcept
488 { return 0 <= rhs.m_order; }
489
491 strong_ordering rhs) noexcept
492 { return 0 > rhs.m_order; }
493
495 strong_ordering rhs) noexcept
496 { return 0 >= rhs.m_order; }
497
498
499#ifdef __cpp_lib_three_way_comparison
500 friend constexpr std::strong_ordering
502 { return lhs; } // https://eel.is/c++draft/cmp.strongord#6
503
504 friend constexpr std::strong_ordering
506 { return QtOrderingPrivate::reversed(rhs); }
507#endif // __cpp_lib_three_way_comparison
508
509
510 friend constexpr bool operator==(strong_ordering lhs, strong_ordering rhs) noexcept
511 { return lhs.m_order == rhs.m_order; }
512
513 friend constexpr bool operator!=(strong_ordering lhs, strong_ordering rhs) noexcept
514 { return lhs.m_order != rhs.m_order; }
515
516 friend constexpr bool operator==(strong_ordering lhs, partial_ordering rhs) noexcept
517 { return static_cast<partial_ordering>(lhs) == rhs; }
518
519 friend constexpr bool operator!=(strong_ordering lhs, partial_ordering rhs) noexcept
520 { return static_cast<partial_ordering>(lhs) == rhs; }
521
522 friend constexpr bool operator==(partial_ordering lhs, strong_ordering rhs) noexcept
523 { return lhs == static_cast<partial_ordering>(rhs); }
524
525 friend constexpr bool operator!=(partial_ordering lhs, strong_ordering rhs) noexcept
526 { return lhs != static_cast<partial_ordering>(rhs); }
527
528 friend constexpr bool operator==(strong_ordering lhs, weak_ordering rhs) noexcept
529 { return static_cast<weak_ordering>(lhs) == rhs; }
530
531 friend constexpr bool operator!=(strong_ordering lhs, weak_ordering rhs) noexcept
532 { return static_cast<weak_ordering>(lhs) == rhs; }
533
534 friend constexpr bool operator==(weak_ordering lhs, strong_ordering rhs) noexcept
535 { return lhs == static_cast<weak_ordering>(rhs); }
536
537 friend constexpr bool operator!=(weak_ordering lhs, strong_ordering rhs) noexcept
538 { return lhs != static_cast<weak_ordering>(rhs); }
539
540#ifdef __cpp_lib_three_way_comparison
542 {
547 else if (stdorder == std::strong_ordering::equal)
549 else if (stdorder == std::strong_ordering::greater)
551 }
552
553 constexpr Q_IMPLICIT operator std::strong_ordering() const noexcept
554 {
555 static_assert(sizeof(*this) == sizeof(std::strong_ordering));
556#ifdef __cpp_lib_bit_cast
557 return std::bit_cast<std::strong_ordering>(*this);
558#else
559 using O = QtPrivate::Ordering;
560 using R = std::strong_ordering;
561 switch (m_order) {
562 case qToUnderlying(O::Less): return R::less;
563 case qToUnderlying(O::Greater): return R::greater;
564 case qToUnderlying(O::Equal): return R::equal;
565 }
567#endif // __cpp_lib_bit_cast
568 }
569
570 friend constexpr bool operator==(strong_ordering lhs, std::strong_ordering rhs) noexcept
571 { return static_cast<std::strong_ordering>(lhs) == rhs; }
572
573 friend constexpr bool operator!=(strong_ordering lhs, std::strong_ordering rhs) noexcept
574 { return static_cast<std::strong_ordering>(lhs) != rhs; }
575
576 friend constexpr bool operator==(strong_ordering lhs, std::partial_ordering rhs) noexcept
577 { return static_cast<std::strong_ordering>(lhs) == rhs; }
578
579 friend constexpr bool operator!=(strong_ordering lhs, std::partial_ordering rhs) noexcept
580 { return static_cast<std::strong_ordering>(lhs) != rhs; }
581
582 friend constexpr bool operator==(strong_ordering lhs, std::weak_ordering rhs) noexcept
583 { return static_cast<std::strong_ordering>(lhs) == rhs; }
584
585 friend constexpr bool operator!=(strong_ordering lhs, std::weak_ordering rhs) noexcept
586 { return static_cast<std::strong_ordering>(lhs) != rhs; }
587
588 friend constexpr bool operator==(std::strong_ordering lhs, strong_ordering rhs) noexcept
589 { return lhs == static_cast<std::strong_ordering>(rhs); }
590
591 friend constexpr bool operator!=(std::strong_ordering lhs, strong_ordering rhs) noexcept
592 { return lhs != static_cast<std::strong_ordering>(rhs); }
593
594 friend constexpr bool operator==(std::partial_ordering lhs, strong_ordering rhs) noexcept
595 { return lhs == static_cast<std::strong_ordering>(rhs); }
596
597 friend constexpr bool operator!=(std::partial_ordering lhs, strong_ordering rhs) noexcept
598 { return lhs != static_cast<std::strong_ordering>(rhs); }
599
600 friend constexpr bool operator==(std::weak_ordering lhs, strong_ordering rhs) noexcept
601 { return lhs == static_cast<std::strong_ordering>(rhs); }
602
603 friend constexpr bool operator!=(std::weak_ordering lhs, strong_ordering rhs) noexcept
604 { return lhs != static_cast<std::strong_ordering>(rhs); }
605#endif // __cpp_lib_three_way_comparison
606
607 private:
608 constexpr explicit strong_ordering(QtPrivate::Ordering order) noexcept
609 : m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
610 {}
611
612 QT_WARNING_PUSH
613 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903
614 QT_WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant")
615 friend constexpr bool is_eq (strong_ordering o) noexcept { return o == 0; }
616 friend constexpr bool is_neq (strong_ordering o) noexcept { return o != 0; }
617 friend constexpr bool is_lt (strong_ordering o) noexcept { return o < 0; }
618 friend constexpr bool is_lteq(strong_ordering o) noexcept { return o <= 0; }
619 friend constexpr bool is_gt (strong_ordering o) noexcept { return o > 0; }
620 friend constexpr bool is_gteq(strong_ordering o) noexcept { return o >= 0; }
622
624};
625
630
631} // namespace Qt
632
633QT_BEGIN_INCLUDE_NAMESPACE
634
635// This is intentionally included after Qt::*_ordering types and before
636// qCompareThreeWay. Do not change!
637#include <QtCore/qcomparehelpers.h>
638
639QT_END_INCLUDE_NAMESPACE
640
641#if defined(Q_QDOC)
642
643template <typename LeftType, typename RightType>
644auto qCompareThreeWay(const LeftType &lhs, const RightType &rhs);
645
646#else
647
648template <typename LT, typename RT,
649 std::enable_if_t<
650 QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay<LT, RT>
651 || QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay<RT, LT>,
652 bool> = true>
653auto qCompareThreeWay(const LT &lhs, const RT &rhs)
654 noexcept(QtOrderingPrivate::CompareThreeWayTester::compareThreeWayNoexcept<LT, RT>())
655{
656 using Qt::compareThreeWay;
657 if constexpr (QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay<LT, RT>) {
658 return compareThreeWay(lhs, rhs);
659 } else {
660 const auto retval = compareThreeWay(rhs, lhs);
661 return QtOrderingPrivate::reversed(retval);
662 }
663}
664
665#endif // defined(Q_QDOC)
666
667//
668// Legacy QPartialOrdering
669//
670
671namespace QtPrivate {
673{
674 Unordered = -127
675};
676}
677
678// [cmp.partialord]
680{
681public:
682 static const QPartialOrdering Less;
686
687 static const QPartialOrdering less;
691
692 friend constexpr bool operator==(QPartialOrdering lhs,
694 { return lhs.isOrdered() && lhs.m_order == 0; }
695
696 friend constexpr bool operator!=(QPartialOrdering lhs,
698 { return !lhs.isOrdered() || lhs.m_order != 0; }
699
700 friend constexpr bool operator< (QPartialOrdering lhs,
702 { return lhs.isOrdered() && lhs.m_order < 0; }
703
704 friend constexpr bool operator<=(QPartialOrdering lhs,
706 { return lhs.isOrdered() && lhs.m_order <= 0; }
707
708 friend constexpr bool operator> (QPartialOrdering lhs,
710 { return lhs.isOrdered() && lhs.m_order > 0; }
711
712 friend constexpr bool operator>=(QPartialOrdering lhs,
714 { return lhs.isOrdered() && lhs.m_order >= 0; }
715
716
718 QPartialOrdering rhs) noexcept
719 { return rhs.isOrdered() && 0 == rhs.m_order; }
720
722 QPartialOrdering rhs) noexcept
723 { return !rhs.isOrdered() || 0 != rhs.m_order; }
724
726 QPartialOrdering rhs) noexcept
727 { return rhs.isOrdered() && 0 < rhs.m_order; }
728
730 QPartialOrdering rhs) noexcept
731 { return rhs.isOrdered() && 0 <= rhs.m_order; }
732
734 QPartialOrdering rhs) noexcept
735 { return rhs.isOrdered() && 0 > rhs.m_order; }
736
738 QPartialOrdering rhs) noexcept
739 { return rhs.isOrdered() && 0 >= rhs.m_order; }
740
741
742#ifdef __cpp_lib_three_way_comparison
743 friend constexpr std::partial_ordering
745 { return lhs; } // https://eel.is/c++draft/cmp.partialord#4
746
747 friend constexpr std::partial_ordering
749 { return QtOrderingPrivate::reversed(rhs); }
750#endif // __cpp_lib_three_way_comparison
751
752
753 friend constexpr bool operator==(QPartialOrdering lhs, QPartialOrdering rhs) noexcept
754 { return lhs.m_order == rhs.m_order; }
755
756 friend constexpr bool operator!=(QPartialOrdering lhs, QPartialOrdering rhs) noexcept
757 { return lhs.m_order != rhs.m_order; }
758
769
772
775
776 constexpr Q_IMPLICIT operator Qt::partial_ordering() const noexcept
777 {
778 using O = QtPrivate::Ordering;
780 using R = Qt::partial_ordering;
781 switch (m_order) {
782 case qToUnderlying(O::Less): return R::less;
783 case qToUnderlying(O::Greater): return R::greater;
784 case qToUnderlying(O::Equivalent): return R::equivalent;
785 case qToUnderlying(U::Unordered): return R::unordered;
786 }
787 // GCC 8.x does not treat __builtin_unreachable() as constexpr
788#if !defined(Q_CC_GNU_ONLY) || (Q_CC_GNU >= 900)
789 // NOLINTNEXTLINE(qt-use-unreachable-return): Triggers on Clang, breaking GCC 8
791#endif
792 return R::unordered;
793 }
794
795 friend constexpr bool operator==(QPartialOrdering lhs, Qt::partial_ordering rhs) noexcept
796 { Qt::partial_ordering qt = lhs; return qt == rhs; }
797
798 friend constexpr bool operator!=(QPartialOrdering lhs, Qt::partial_ordering rhs) noexcept
799 { Qt::partial_ordering qt = lhs; return qt != rhs; }
800
801 friend constexpr bool operator==(Qt::partial_ordering lhs, QPartialOrdering rhs) noexcept
802 { Qt::partial_ordering qt = rhs; return lhs == qt; }
803
804 friend constexpr bool operator!=(Qt::partial_ordering lhs, QPartialOrdering rhs) noexcept
805 { Qt::partial_ordering qt = rhs; return lhs != qt; }
806
807#ifdef __cpp_lib_three_way_comparison
809 {
814 else if (stdorder == std::partial_ordering::greater)
818 }
819
822
825
826 constexpr Q_IMPLICIT operator std::partial_ordering() const noexcept
827 {
828 using O = QtPrivate::Ordering;
830 using R = std::partial_ordering;
831 switch (m_order) {
832 case qToUnderlying(O::Less): return R::less;
833 case qToUnderlying(O::Greater): return R::greater;
834 case qToUnderlying(O::Equivalent): return R::equivalent;
835 case qToUnderlying(U::Unordered): return R::unordered;
836 }
838 }
839
840 friend constexpr bool operator==(QPartialOrdering lhs, std::partial_ordering rhs) noexcept
841 { return static_cast<std::partial_ordering>(lhs) == rhs; }
842
843 friend constexpr bool operator!=(QPartialOrdering lhs, std::partial_ordering rhs) noexcept
844 { return static_cast<std::partial_ordering>(lhs) != rhs; }
845
846 friend constexpr bool operator==(std::partial_ordering lhs, QPartialOrdering rhs) noexcept
847 { return lhs == static_cast<std::partial_ordering>(rhs); }
848
849 friend constexpr bool operator!=(std::partial_ordering lhs, QPartialOrdering rhs) noexcept
850 { return lhs != static_cast<std::partial_ordering>(rhs); }
851#endif // __cpp_lib_three_way_comparison
852
853private:
854 constexpr explicit QPartialOrdering(QtPrivate::Ordering order) noexcept
855 : m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
856 {}
857 constexpr explicit QPartialOrdering(QtPrivate::LegacyUncomparable order) noexcept
858 : m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
859 {}
860
861 QT_WARNING_PUSH
862 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903
863 QT_WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant")
864 friend constexpr bool is_eq (QPartialOrdering o) noexcept { return o == 0; }
865 friend constexpr bool is_neq (QPartialOrdering o) noexcept { return o != 0; }
866 friend constexpr bool is_lt (QPartialOrdering o) noexcept { return o < 0; }
867 friend constexpr bool is_lteq(QPartialOrdering o) noexcept { return o <= 0; }
868 friend constexpr bool is_gt (QPartialOrdering o) noexcept { return o > 0; }
869 friend constexpr bool is_gteq(QPartialOrdering o) noexcept { return o >= 0; }
871
872 // instead of the exposition only is_ordered member in [cmp.partialord],
873 // use a private function
874 constexpr bool isOrdered() const noexcept
876
878};
879
884
889
890QT_END_NAMESPACE
891
892#endif // QCOMPARE_H
\variable Qt::partial_ordering::less
Definition qcompare.h:680
friend constexpr bool operator==(QPartialOrdering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:692
static const QPartialOrdering unordered
Definition qcompare.h:690
friend constexpr bool operator==(QPartialOrdering lhs, Qt::partial_ordering rhs) noexcept
Definition qcompare.h:795
static const QPartialOrdering greater
Definition qcompare.h:689
friend constexpr bool operator<(QtPrivate::CompareAgainstLiteralZero, QPartialOrdering rhs) noexcept
Definition qcompare.h:725
friend constexpr bool operator<(QPartialOrdering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:700
static const QPartialOrdering less
Definition qcompare.h:687
friend constexpr bool operator!=(QPartialOrdering lhs, Qt::partial_ordering rhs) noexcept
Definition qcompare.h:798
friend constexpr bool operator==(QtPrivate::CompareAgainstLiteralZero, QPartialOrdering rhs) noexcept
Definition qcompare.h:717
friend constexpr bool operator==(Qt::partial_ordering lhs, QPartialOrdering rhs) noexcept
Definition qcompare.h:801
friend constexpr bool operator>(QPartialOrdering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:708
static const QPartialOrdering Less
Definition qcompare.h:682
friend constexpr bool operator>=(QtPrivate::CompareAgainstLiteralZero, QPartialOrdering rhs) noexcept
Definition qcompare.h:737
friend constexpr bool operator==(QPartialOrdering lhs, QPartialOrdering rhs) noexcept
Return true if lhs and rhs represent the same result; otherwise, returns false.
Definition qcompare.h:753
static const QPartialOrdering equivalent
Definition qcompare.h:688
friend constexpr bool operator!=(Qt::partial_ordering lhs, QPartialOrdering rhs) noexcept
Definition qcompare.h:804
friend constexpr bool operator!=(QtPrivate::CompareAgainstLiteralZero, QPartialOrdering rhs) noexcept
Definition qcompare.h:721
friend constexpr bool operator<=(QPartialOrdering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:704
friend constexpr bool operator!=(QPartialOrdering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:696
friend constexpr bool operator!=(QPartialOrdering lhs, QPartialOrdering rhs) noexcept
Return true if lhs and rhs represent different results; otherwise, returns true.
Definition qcompare.h:756
friend constexpr bool operator>(QtPrivate::CompareAgainstLiteralZero, QPartialOrdering rhs) noexcept
Definition qcompare.h:733
static const QPartialOrdering Greater
Definition qcompare.h:684
friend constexpr bool operator<=(QtPrivate::CompareAgainstLiteralZero, QPartialOrdering rhs) noexcept
Definition qcompare.h:729
static const QPartialOrdering Equivalent
Definition qcompare.h:683
static const QPartialOrdering Unordered
Definition qcompare.h:685
friend constexpr bool operator>=(QPartialOrdering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:712
\variable Qt::weak_ordering::less
Definition qcompare.h:78
friend constexpr bool operator>=(QtPrivate::CompareAgainstLiteralZero, partial_ordering rhs) noexcept
Definition qcompare.h:130
friend constexpr bool operator>(partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:101
friend constexpr bool operator>(QtPrivate::CompareAgainstLiteralZero, partial_ordering rhs) noexcept
Definition qcompare.h:126
friend constexpr bool operator==(QtPrivate::CompareAgainstLiteralZero, partial_ordering rhs) noexcept
Definition qcompare.h:110
friend constexpr bool operator<=(partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:97
static const partial_ordering equivalent
Definition qcompare.h:81
friend constexpr bool operator<=(QtPrivate::CompareAgainstLiteralZero, partial_ordering rhs) noexcept
Definition qcompare.h:122
friend constexpr bool operator==(partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:85
friend constexpr bool operator!=(QtPrivate::CompareAgainstLiteralZero, partial_ordering rhs) noexcept
Definition qcompare.h:114
friend constexpr bool operator!=(partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:89
friend constexpr bool operator<(partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:93
friend constexpr bool operator<(QtPrivate::CompareAgainstLiteralZero, partial_ordering rhs) noexcept
Definition qcompare.h:118
static const partial_ordering unordered
Definition qcompare.h:83
friend constexpr bool operator>=(partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:105
static const partial_ordering greater
Definition qcompare.h:82
friend constexpr bool operator!=(partial_ordering lhs, partial_ordering rhs) noexcept
Return true if lhs and rhs represent different results; otherwise, returns true.
Definition qcompare.h:149
static const partial_ordering less
Definition qcompare.h:80
friend constexpr bool operator==(partial_ordering lhs, partial_ordering rhs) noexcept
Return true if lhs and rhs represent the same result; otherwise, returns false.
Definition qcompare.h:146
\inmodule QtCore \title Classes and helpers for defining comparison operators \keyword qtcompare
Definition qcompare.h:436
friend constexpr bool operator<=(strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:461
friend constexpr bool operator!=(strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:453
friend constexpr bool operator<(strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:457
friend constexpr bool operator<(QtPrivate::CompareAgainstLiteralZero, strong_ordering rhs) noexcept
Definition qcompare.h:482
static const strong_ordering greater
Definition qcompare.h:441
friend constexpr bool operator==(strong_ordering lhs, partial_ordering rhs) noexcept
Definition qcompare.h:516
friend constexpr bool operator>(strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:465
friend constexpr bool operator!=(weak_ordering lhs, strong_ordering rhs) noexcept
Definition qcompare.h:537
friend constexpr bool operator!=(partial_ordering lhs, strong_ordering rhs) noexcept
Definition qcompare.h:525
static const strong_ordering equal
Definition qcompare.h:440
friend constexpr bool operator!=(QtPrivate::CompareAgainstLiteralZero, strong_ordering rhs) noexcept
Definition qcompare.h:478
friend constexpr bool operator==(QtPrivate::CompareAgainstLiteralZero, strong_ordering rhs) noexcept
Definition qcompare.h:474
friend constexpr bool operator==(strong_ordering lhs, weak_ordering rhs) noexcept
Definition qcompare.h:528
friend constexpr bool operator>=(QtPrivate::CompareAgainstLiteralZero, strong_ordering rhs) noexcept
Definition qcompare.h:494
static const strong_ordering less
Definition qcompare.h:438
friend constexpr bool operator!=(strong_ordering lhs, weak_ordering rhs) noexcept
Definition qcompare.h:531
friend constexpr bool operator!=(strong_ordering lhs, partial_ordering rhs) noexcept
Definition qcompare.h:519
friend constexpr bool operator==(strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:449
static const strong_ordering equivalent
Definition qcompare.h:439
friend constexpr bool operator>(QtPrivate::CompareAgainstLiteralZero, strong_ordering rhs) noexcept
Definition qcompare.h:490
friend constexpr bool operator<=(QtPrivate::CompareAgainstLiteralZero, strong_ordering rhs) noexcept
Definition qcompare.h:486
friend constexpr bool operator==(strong_ordering lhs, strong_ordering rhs) noexcept
Returns true if lhs and rhs represent the same result; otherwise, returns false.
Definition qcompare.h:510
friend constexpr bool operator!=(strong_ordering lhs, strong_ordering rhs) noexcept
Returns true if lhs and rhs represent different results; otherwise, returns true.
Definition qcompare.h:513
friend constexpr bool operator==(weak_ordering lhs, strong_ordering rhs) noexcept
Definition qcompare.h:534
friend constexpr bool operator==(partial_ordering lhs, strong_ordering rhs) noexcept
Definition qcompare.h:522
friend constexpr bool operator>=(strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:469
\variable Qt::strong_ordering::less
Definition qcompare.h:257
friend constexpr bool operator!=(weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:270
static const weak_ordering less
Definition qcompare.h:259
friend constexpr bool operator<=(weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:278
friend constexpr bool operator<(weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:274
friend constexpr bool operator==(weak_ordering lhs, partial_ordering rhs) noexcept
Definition qcompare.h:333
friend constexpr bool operator<(QtPrivate::CompareAgainstLiteralZero, weak_ordering rhs) noexcept
Definition qcompare.h:299
friend constexpr bool operator>(QtPrivate::CompareAgainstLiteralZero, weak_ordering rhs) noexcept
Definition qcompare.h:307
friend constexpr bool operator==(weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:266
friend constexpr bool operator!=(QtPrivate::CompareAgainstLiteralZero, weak_ordering rhs) noexcept
Definition qcompare.h:295
friend constexpr bool operator>=(weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:286
friend constexpr bool operator==(weak_ordering lhs, weak_ordering rhs) noexcept
Return true if lhs and rhs represent the same result; otherwise, returns false.
Definition qcompare.h:327
friend constexpr bool operator>=(QtPrivate::CompareAgainstLiteralZero, weak_ordering rhs) noexcept
Definition qcompare.h:311
static const weak_ordering greater
Definition qcompare.h:261
friend constexpr bool operator>(weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
Definition qcompare.h:282
friend constexpr bool operator!=(weak_ordering lhs, weak_ordering rhs) noexcept
Return true if lhs and rhs represent different results; otherwise, returns true.
Definition qcompare.h:330
friend constexpr bool operator!=(weak_ordering lhs, partial_ordering rhs) noexcept
Definition qcompare.h:336
friend constexpr bool operator<=(QtPrivate::CompareAgainstLiteralZero, weak_ordering rhs) noexcept
Definition qcompare.h:303
friend constexpr bool operator!=(partial_ordering lhs, weak_ordering rhs) noexcept
Definition qcompare.h:342
friend constexpr bool operator==(partial_ordering lhs, weak_ordering rhs) noexcept
Definition qcompare.h:339
static const weak_ordering equivalent
Definition qcompare.h:260
friend constexpr bool operator==(QtPrivate::CompareAgainstLiteralZero, weak_ordering rhs) noexcept
Definition qcompare.h:291
Combined button and popup list for selecting options.
constexpr O reversed(O o) noexcept
Definition qcompare.h:62
\macro QT_NO_KEYWORDS >
Definition qcompare.h:24
LegacyUncomparable
Definition qcompare.h:673
Definition qcompare.h:72