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 // <optional> 11 12 // template <class T> constexpr bool operator>(const optional<T>& x, const T& v); 13 // template <class T> constexpr bool operator>(const T& v, const optional<T>& x); 14 15 #include <experimental/optional> 16 17 #if _LIBCPP_STD_VER > 11 18 19 using std::experimental::optional; 20 21 struct X 22 { 23 int i_; 24 25 constexpr X(int i) : i_(i) {} 26 }; 27 28 constexpr bool operator < ( const X &lhs, const X &rhs ) 29 { return lhs.i_ < rhs.i_ ; } 30 31 #endif 32 33 int main() 34 { 35 #if _LIBCPP_STD_VER > 11 36 37 { 38 typedef X T; 39 typedef optional<T> O; 40 41 constexpr T val(2); 42 constexpr O o1; // disengaged 43 constexpr O o2{1}; // engaged 44 constexpr O o3{val}; // engaged 45 46 static_assert ( !(o1 > T(1)), "" ); 47 static_assert ( !(o2 > T(1)), "" ); // equal 48 static_assert ( (o3 > T(1)), "" ); 49 static_assert ( !(o2 > val), "" ); 50 static_assert ( !(o3 > val), "" ); // equal 51 static_assert ( !(o3 > T(3)), "" ); 52 53 static_assert ( (T(1) > o1), "" ); 54 static_assert ( !(T(1) > o2), "" ); // equal 55 static_assert ( !(T(1) > o3), "" ); 56 static_assert ( (val > o2), "" ); 57 static_assert ( !(val > o3), "" ); // equal 58 static_assert ( (T(3) > o3), "" ); 59 } 60 #endif 61 } 62