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