equal.pass.cpp revision 2faa02fc3d44e081fb7e3f36b19de622959aeb8c
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 optional<T>& y); 13 14#include <optional> 15#include <type_traits> 16#include <cassert> 17 18#if _LIBCPP_STD_VER > 11 19 20struct X 21{ 22 int i_; 23 24 constexpr X(int i) : i_(i) {} 25}; 26 27constexpr bool operator == ( const X &rhs, const X &lhs ) 28 { return rhs.i_ == lhs.i_ ; } 29 30#endif 31 32int main() 33{ 34#if _LIBCPP_STD_VER > 11 35 { 36 typedef X T; 37 typedef std::optional<T> O; 38 39 constexpr O o1; // disengaged 40 constexpr O o2; // disengaged 41 constexpr O o3{1}; // engaged 42 constexpr O o4{2}; // engaged 43 constexpr O o5{1}; // engaged 44 45 static_assert ( o1 == o1 , "" ); 46 static_assert ( o1 == o2 , "" ); 47 static_assert ( !(o1 == o3), "" ); 48 static_assert ( !(o1 == o4), "" ); 49 static_assert ( !(o1 == o5), "" ); 50 51 static_assert ( o2 == o1 , "" ); 52 static_assert ( o2 == o2 , "" ); 53 static_assert ( !(o2 == o3), "" ); 54 static_assert ( !(o2 == o4), "" ); 55 static_assert ( !(o2 == o5), "" ); 56 57 static_assert ( !(o3 == o1), "" ); 58 static_assert ( !(o3 == o2), "" ); 59 static_assert ( o3 == o3 , "" ); 60 static_assert ( !(o3 == o4), "" ); 61 static_assert ( o3 == o5 , "" ); 62 63 static_assert ( !(o4 == o1), "" ); 64 static_assert ( !(o4 == o2), "" ); 65 static_assert ( !(o4 == o3), "" ); 66 static_assert ( o4 == o4 , "" ); 67 static_assert ( !(o4 == o5), "" ); 68 69 static_assert ( !(o5 == o1), "" ); 70 static_assert ( !(o5 == o2), "" ); 71 static_assert ( o5 == o3 , "" ); 72 static_assert ( !(o5 == o4), "" ); 73 static_assert ( o5 == o5 , "" ); 74 75 } 76#endif 77} 78