equal.pass.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03, c++11, c++14
  9. // <optional>
  10. // template <class T> constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept;
  11. // template <class T> constexpr bool operator==(nullopt_t, const optional<T>& x) noexcept;
  12. #include <optional>
  13. #include "test_macros.h"
  14. int main(int, char**)
  15. {
  16. using std::optional;
  17. using std::nullopt_t;
  18. using std::nullopt;
  19. {
  20. typedef int T;
  21. typedef optional<T> O;
  22. constexpr O o1; // disengaged
  23. constexpr O o2{1}; // engaged
  24. static_assert ( (nullopt == o1), "" );
  25. static_assert ( !(nullopt == o2), "" );
  26. static_assert ( (o1 == nullopt), "" );
  27. static_assert ( !(o2 == nullopt), "" );
  28. static_assert (noexcept(nullopt == o1), "");
  29. static_assert (noexcept(o1 == nullopt), "");
  30. }
  31. return 0;
  32. }