2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_COMPARE
11 #define _LIBCPP_COMPARE
17 // [cmp.categories], comparison category types
18 class partial_ordering;
20 class strong_ordering;
22 // named comparison functions
23 constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; }
24 constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
25 constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; }
26 constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
27 constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; }
28 constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; }
30 // [cmp.common], common comparison category type
32 struct common_comparison_category {
33 using type = see below;
36 using common_comparison_category_t = typename common_comparison_category<Ts...>::type;
38 // [cmp.concept], concept three_way_comparable
39 template<class T, class Cat = partial_ordering>
40 concept three_way_comparable = see below;
41 template<class T, class U, class Cat = partial_ordering>
42 concept three_way_comparable_with = see below;
44 // [cmp.result], result of three-way comparison
45 template<class T, class U = T> struct compare_three_way_result;
47 template<class T, class U = T>
48 using compare_three_way_result_t = typename compare_three_way_result<T, U>::type;
50 // [comparisons.three.way], class compare_three_way
51 struct compare_three_way; // C++20
53 // [cmp.alg], comparison algorithms
54 inline namespace unspecified {
55 inline constexpr unspecified strong_order = unspecified;
56 inline constexpr unspecified weak_order = unspecified;
57 inline constexpr unspecified partial_order = unspecified;
58 inline constexpr unspecified compare_strong_order_fallback = unspecified;
59 inline constexpr unspecified compare_weak_order_fallback = unspecified;
60 inline constexpr unspecified compare_partial_order_fallback = unspecified;
63 // [cmp.partialord], Class partial_ordering
64 class partial_ordering {
67 static const partial_ordering less;
68 static const partial_ordering equivalent;
69 static const partial_ordering greater;
70 static const partial_ordering unordered;
73 friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
74 friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
75 friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
76 friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
77 friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
78 friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
79 friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
80 friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
81 friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
82 friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
83 friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
84 friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
87 // [cmp.weakord], Class weak_ordering
91 static const weak_ordering less;
92 static const weak_ordering equivalent;
93 static const weak_ordering greater;
96 constexpr operator partial_ordering() const noexcept;
99 friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
100 friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
101 friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
102 friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
103 friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
104 friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
105 friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
106 friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
107 friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
108 friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
109 friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
110 friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
113 // [cmp.strongord], Class strong_ordering
114 class strong_ordering {
117 static const strong_ordering less;
118 static const strong_ordering equal;
119 static const strong_ordering equivalent;
120 static const strong_ordering greater;
123 constexpr operator partial_ordering() const noexcept;
124 constexpr operator weak_ordering() const noexcept;
127 friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
128 friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
129 friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
130 friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
131 friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
132 friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
133 friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
134 friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
135 friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
136 friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
137 friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
138 friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
143 #include <__assert> // all public C++ headers provide the assertion handler
144 #include <__compare/common_comparison_category.h>
145 #include <__compare/compare_partial_order_fallback.h>
146 #include <__compare/compare_strong_order_fallback.h>
147 #include <__compare/compare_three_way.h>
148 #include <__compare/compare_three_way_result.h>
149 #include <__compare/compare_weak_order_fallback.h>
150 #include <__compare/is_eq.h>
151 #include <__compare/ordering.h>
152 #include <__compare/partial_order.h>
153 #include <__compare/strong_order.h>
154 #include <__compare/synth_three_way.h>
155 #include <__compare/three_way_comparable.h>
156 #include <__compare/weak_order.h>
160 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
161 # pragma GCC system_header
164 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
165 # include <type_traits>
168 #endif // _LIBCPP_COMPARE