Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / optional / optional.comp_with_t / less_than.pass.cpp
blobb3d98684ba20b0209f86a8508296d4001cf5ea88
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
10 // <optional>
12 // template <class T, class U> constexpr bool operator<(const optional<T>& x, const U& v);
13 // template <class T, class U> constexpr bool operator<(const U& v, const optional<T>& x);
15 #include <optional>
17 #include "test_macros.h"
19 using std::optional;
21 struct X {
22 int i_;
24 constexpr X(int i) : i_(i) {}
27 constexpr bool operator<(const X& lhs, const X& rhs) { return lhs.i_ < rhs.i_; }
29 int main(int, char**) {
31 typedef X T;
32 typedef optional<T> O;
34 constexpr T val(2);
35 constexpr O o1; // disengaged
36 constexpr O o2{1}; // engaged
37 constexpr O o3{val}; // engaged
39 static_assert((o1 < T(1)), "");
40 static_assert(!(o2 < T(1)), ""); // equal
41 static_assert(!(o3 < T(1)), "");
42 static_assert((o2 < val), "");
43 static_assert(!(o3 < val), ""); // equal
44 static_assert((o3 < T(3)), "");
46 static_assert(!(T(1) < o1), "");
47 static_assert(!(T(1) < o2), ""); // equal
48 static_assert((T(1) < o3), "");
49 static_assert(!(val < o2), "");
50 static_assert(!(val < o3), ""); // equal
51 static_assert(!(T(3) < o3), "");
54 using O = optional<int>;
55 constexpr O o1(42);
56 static_assert(o1 < 101l, "");
57 static_assert(!(42l < o1), "");
60 using O = optional<const int>;
61 constexpr O o1(42);
62 static_assert(o1 < 101, "");
63 static_assert(!(42 < o1), "");
66 return 0;