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 // [optional.relops], relational operators
15 // template<class T, three_way_comparable_with<T> U>
16 // constexpr compare_three_way_result_t<T, U>
17 // operator<=>(const optional<T>&, const optional<U>&);
23 #include "test_comparisons.h"
25 constexpr bool test() {
27 std::optional
<int> op1
;
28 std::optional
<int> op2
;
30 assert((op1
<=> op2
) == std::strong_ordering::equal
);
31 assert(testOrder(op1
, op2
, std::strong_ordering::equal
));
34 std::optional
<int> op1
{3};
35 std::optional
<int> op2
{3};
36 assert((op1
<=> op1
) == std::strong_ordering::equal
);
37 assert(testOrder(op1
, op1
, std::strong_ordering::equal
));
38 assert((op1
<=> op2
) == std::strong_ordering::equal
);
39 assert(testOrder(op1
, op2
, std::strong_ordering::equal
));
40 assert((op2
<=> op1
) == std::strong_ordering::equal
);
41 assert(testOrder(op2
, op1
, std::strong_ordering::equal
));
44 std::optional
<int> op
;
45 std::optional
<int> op1
{2};
46 std::optional
<int> op2
{3};
47 assert((op
<=> op2
) == std::strong_ordering::less
);
48 assert(testOrder(op
, op2
, std::strong_ordering::less
));
49 assert((op1
<=> op2
) == std::strong_ordering::less
);
50 assert(testOrder(op1
, op2
, std::strong_ordering::less
));
53 std::optional
<int> op
;
54 std::optional
<int> op1
{3};
55 std::optional
<int> op2
{2};
56 assert((op1
<=> op
) == std::strong_ordering::greater
);
57 assert(testOrder(op1
, op
, std::strong_ordering::greater
));
58 assert((op1
<=> op2
) == std::strong_ordering::greater
);
59 assert(testOrder(op1
, op2
, std::strong_ordering::greater
));
65 int main(int, char**) {
67 static_assert(test());