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 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++98, c++03, c++11, c++14
10 // <optional>
11 
12 // template <class T, class U> constexpr bool operator< (const optional<T>& x, const optional<U>& y);
13 
14 #include <optional>
15 
16 using std::optional;
17 
18 struct X {
19   int i_;
20 
21   constexpr X(int i) : i_(i) {}
22 };
23 
24 constexpr bool operator<(const X& lhs, const X& rhs) { return lhs.i_ < rhs.i_; }
25 
26 int main(int, char**) {
27   {
28     typedef optional<X> O;
29 
30     constexpr O o1;    // disengaged
31     constexpr O o2;    // disengaged
32     constexpr O o3{1}; // engaged
33     constexpr O o4{2}; // engaged
34     constexpr O o5{1}; // engaged
35 
36     static_assert(!(o1 < o1), "");
37     static_assert(!(o1 < o2), "");
38     static_assert((o1 < o3), "");
39     static_assert((o1 < o4), "");
40     static_assert((o1 < o5), "");
41 
42     static_assert(!(o2 < o1), "");
43     static_assert(!(o2 < o2), "");
44     static_assert((o2 < o3), "");
45     static_assert((o2 < o4), "");
46     static_assert((o2 < o5), "");
47 
48     static_assert(!(o3 < o1), "");
49     static_assert(!(o3 < o2), "");
50     static_assert(!(o3 < o3), "");
51     static_assert((o3 < o4), "");
52     static_assert(!(o3 < o5), "");
53 
54     static_assert(!(o4 < o1), "");
55     static_assert(!(o4 < o2), "");
56     static_assert(!(o4 < o3), "");
57     static_assert(!(o4 < o4), "");
58     static_assert(!(o4 < o5), "");
59 
60     static_assert(!(o5 < o1), "");
61     static_assert(!(o5 < o2), "");
62     static_assert(!(o5 < o3), "");
63     static_assert((o5 < o4), "");
64     static_assert(!(o5 < o5), "");
65   }
66   {
67     using O1 = optional<int>;
68     using O2 = optional<long>;
69     constexpr O1 o1(42);
70     static_assert(o1 < O2(101), "");
71     static_assert(!(O2(101) < o1), "");
72   }
73   {
74     using O1 = optional<int>;
75     using O2 = optional<const int>;
76     constexpr O1 o1(42);
77     static_assert(o1 < O2(101), "");
78     static_assert(!(O2(101) < o1), "");
79   }
80 
81   return 0;
82 }
83