equal.pass.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // UNSUPPORTED: c++98, c++03, c++11
  10. // <optional>
  11. // template <class T> constexpr bool operator==(const optional<T>& x, const T& v);
  12. // template <class T> constexpr bool operator==(const T& v, const optional<T>& x);
  13. #include <experimental/optional>
  14. using std::experimental::optional;
  15. struct X
  16. {
  17. int i_;
  18. constexpr X(int i) : i_(i) {}
  19. };
  20. constexpr bool operator == ( const X &lhs, const X &rhs )
  21. { return lhs.i_ == rhs.i_ ; }
  22. int main()
  23. {
  24. {
  25. typedef X T;
  26. typedef optional<T> O;
  27. constexpr T val(2);
  28. constexpr O o1; // disengaged
  29. constexpr O o2{1}; // engaged
  30. constexpr O o3{val}; // engaged
  31. static_assert ( !(o1 == T(1)), "" );
  32. static_assert ( (o2 == T(1)), "" );
  33. static_assert ( !(o3 == T(1)), "" );
  34. static_assert ( (o3 == T(2)), "" );
  35. static_assert ( (o3 == val), "" );
  36. static_assert ( !(T(1) == o1), "" );
  37. static_assert ( (T(1) == o2), "" );
  38. static_assert ( !(T(1) == o3), "" );
  39. static_assert ( (T(2) == o3), "" );
  40. static_assert ( (val == o3), "" );
  41. }
  42. }