1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 // <optional>
12
13 // template <class T, class U> constexpr bool operator<(const optional<T>& x, const U& v);
14 // template <class T, class U> constexpr bool operator<(const U& v, const optional<T>& x);
15
16 #include <optional>
17
18 using std::optional;
19
20 struct X {
21 int i_;
22
XX23 constexpr X(int i) : i_(i) {}
24 };
25
operator <(const X & lhs,const X & rhs)26 constexpr bool operator<(const X& lhs, const X& rhs) { return lhs.i_ < rhs.i_; }
27
main()28 int main() {
29 {
30 typedef X T;
31 typedef optional<T> O;
32
33 constexpr T val(2);
34 constexpr O o1; // disengaged
35 constexpr O o2{1}; // engaged
36 constexpr O o3{val}; // engaged
37
38 static_assert((o1 < T(1)), "");
39 static_assert(!(o2 < T(1)), ""); // equal
40 static_assert(!(o3 < T(1)), "");
41 static_assert((o2 < val), "");
42 static_assert(!(o3 < val), ""); // equal
43 static_assert((o3 < T(3)), "");
44
45 static_assert(!(T(1) < o1), "");
46 static_assert(!(T(1) < o2), ""); // equal
47 static_assert((T(1) < o3), "");
48 static_assert(!(val < o2), "");
49 static_assert(!(val < o3), ""); // equal
50 static_assert(!(T(3) < o3), "");
51 }
52 {
53 using O = optional<int>;
54 constexpr O o1(42);
55 static_assert(o1 < 101l, "");
56 static_assert(!(42l < o1), "");
57 }
58 {
59 using O = optional<const int>;
60 constexpr O o1(42);
61 static_assert(o1 < 101, "");
62 static_assert(!(42 < o1), "");
63 }
64 }
65