Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / optional / optional.relops / compare.three_way.pass.cpp
blobb00fe46f37ff5e3eb100f0e139efaab02d2b3958
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // <optional>
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>&);
19 #include <cassert>
20 #include <compare>
21 #include <optional>
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));
62 return true;
65 int main(int, char**) {
66 assert(test());
67 static_assert(test());
68 return 0;