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 typedef X T; 38 typedef optional<T> O; 39 40 constexpr T val(2); 41 constexpr O o1; // disengaged 42 constexpr O o2{1}; // engaged 43 constexpr O o3{val}; // engaged 44 45 static_assert ( (o1 != T(1)), "" ); 46 static_assert ( !(o2 != T(1)), "" ); 47 static_assert ( (o3 != T(1)), "" ); 48 static_assert ( !(o3 != T(2)), "" ); 49 static_assert ( !(o3 != val), "" ); 50 51 static_assert ( (T(1) != o1), "" ); 52 static_assert ( !(T(1) != o2), "" ); 53 static_assert ( (T(1) != o3), "" ); 54 static_assert ( !(T(2) != o3), "" ); 55 static_assert ( !(val != o3), "" ); 56 } 57 #endif 58 } 59