holds_alternative.pass.cpp 1.0 KB

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