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