has_value.pass.cpp 953 B

12345678910111213141516171819202122232425262728293031323334353637
  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. // constexpr bool optional<T>::has_value() const noexcept;
  12. #include <optional>
  13. #include <type_traits>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. int main()
  17. {
  18. using std::optional;
  19. {
  20. const optional<int> opt; ((void)opt);
  21. ASSERT_NOEXCEPT(opt.has_value());
  22. ASSERT_SAME_TYPE(decltype(opt.has_value()), bool);
  23. }
  24. {
  25. constexpr optional<int> opt;
  26. static_assert(!opt.has_value(), "");
  27. }
  28. {
  29. constexpr optional<int> opt(0);
  30. static_assert(opt.has_value(), "");
  31. }
  32. }