1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
13 // class partial_ordering
17 #include <type_traits>
20 #include "test_macros.h"
22 const volatile void* volatile sink
;
24 void test_static_members() {
25 DoNotOptimize(&std::partial_ordering::less
);
26 DoNotOptimize(&std::partial_ordering::equivalent
);
27 DoNotOptimize(&std::partial_ordering::greater
);
28 DoNotOptimize(&std::partial_ordering::unordered
);
31 void test_signatures() {
32 auto& Eq
= std::partial_ordering::equivalent
;
34 ASSERT_NOEXCEPT(Eq
== 0);
35 ASSERT_NOEXCEPT(0 == Eq
);
36 ASSERT_NOEXCEPT(Eq
!= 0);
37 ASSERT_NOEXCEPT(0 != Eq
);
38 ASSERT_NOEXCEPT(0 < Eq
);
39 ASSERT_NOEXCEPT(Eq
< 0);
40 ASSERT_NOEXCEPT(0 <= Eq
);
41 ASSERT_NOEXCEPT(Eq
<= 0);
42 ASSERT_NOEXCEPT(0 > Eq
);
43 ASSERT_NOEXCEPT(Eq
> 0);
44 ASSERT_NOEXCEPT(0 >= Eq
);
45 ASSERT_NOEXCEPT(Eq
>= 0);
46 ASSERT_NOEXCEPT(0 <=> Eq
);
47 ASSERT_NOEXCEPT(Eq
<=> 0);
48 ASSERT_SAME_TYPE(decltype(Eq
<=> 0), std::partial_ordering
);
49 ASSERT_SAME_TYPE(decltype(0 <=> Eq
), std::partial_ordering
);
52 constexpr void test_equality() {
53 auto& PartialEq
= std::partial_ordering::equivalent
;
54 auto& WeakEq
= std::weak_ordering::equivalent
;
55 assert(PartialEq
== WeakEq
);
57 auto& StrongEq
= std::strong_ordering::equal
;
58 assert(PartialEq
== StrongEq
);
61 constexpr bool test_constexpr() {
62 auto& Eq
= std::partial_ordering::equivalent
;
63 auto& Less
= std::partial_ordering::less
;
64 auto& Greater
= std::partial_ordering::greater
;
65 auto& Unord
= std::partial_ordering::unordered
;
67 std::partial_ordering Value
;
73 {Eq
, true, false, false, false},
74 {Less
, false, true, true, false},
75 {Greater
, false, true, false, true},
76 {Unord
, false, true, false, false}
78 for (auto TC
: TestCases
) {
80 assert((V
== 0) == TC
.ExpectEq
);
81 assert((0 == V
) == TC
.ExpectEq
);
82 assert((V
!= 0) == TC
.ExpectNeq
);
83 assert((0 != V
) == TC
.ExpectNeq
);
85 assert((V
< 0) == TC
.ExpectLess
);
86 assert((V
> 0) == TC
.ExpectGreater
);
87 assert((V
<= 0) == (TC
.ExpectLess
|| TC
.ExpectEq
));
88 assert((V
>= 0) == (TC
.ExpectGreater
|| TC
.ExpectEq
));
90 assert((0 < V
) == TC
.ExpectGreater
);
91 assert((0 > V
) == TC
.ExpectLess
);
92 assert((0 <= V
) == (TC
.ExpectGreater
|| TC
.ExpectEq
));
93 assert((0 >= V
) == (TC
.ExpectLess
|| TC
.ExpectEq
));
96 std::partial_ordering res
= (Eq
<=> 0);
108 std::partial_ordering Value
;
110 } SpaceshipTestCases
[] = {
111 {std::partial_ordering::equivalent
, ER_Equiv
},
112 {std::partial_ordering::less
, ER_Less
},
113 {std::partial_ordering::greater
, ER_Greater
},
114 {std::partial_ordering::unordered
, ER_Unord
}
116 for (auto TC
: SpaceshipTestCases
)
118 std::partial_ordering Res
= (TC
.Value
<=> 0);
133 assert((Res
< 0) == false);
134 assert((Res
> 0) == false);
135 assert((Res
== 0) == false);
140 static_assert(std::partial_ordering::less
== std::partial_ordering::less
);
141 static_assert(std::partial_ordering::less
!=
142 std::partial_ordering::equivalent
);
143 static_assert(std::partial_ordering::less
!=
144 std::partial_ordering::greater
);
145 static_assert(std::partial_ordering::less
!=
146 std::partial_ordering::unordered
);
148 static_assert(std::partial_ordering::equivalent
!=
149 std::partial_ordering::less
);
150 static_assert(std::partial_ordering::equivalent
==
151 std::partial_ordering::equivalent
);
152 static_assert(std::partial_ordering::equivalent
!=
153 std::partial_ordering::greater
);
154 static_assert(std::partial_ordering::equivalent
!=
155 std::partial_ordering::unordered
);
157 static_assert(std::partial_ordering::greater
!=
158 std::partial_ordering::less
);
159 static_assert(std::partial_ordering::greater
!=
160 std::partial_ordering::equivalent
);
161 static_assert(std::partial_ordering::greater
==
162 std::partial_ordering::greater
);
163 static_assert(std::partial_ordering::greater
!=
164 std::partial_ordering::unordered
);
166 static_assert(std::partial_ordering::unordered
!=
167 std::partial_ordering::less
);
168 static_assert(std::partial_ordering::unordered
!=
169 std::partial_ordering::equivalent
);
170 static_assert(std::partial_ordering::unordered
!=
171 std::partial_ordering::greater
);
172 static_assert(std::partial_ordering::unordered
==
173 std::partial_ordering::unordered
);
181 int main(int, char**) {
182 test_static_members();
185 static_assert(test_constexpr(), "constexpr test failed");