equal.pass.cpp 1.9 KB

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