variant_size.pass.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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> struct variant_size; // undefined
  12. // template <class T> struct variant_size<const T>;
  13. // template <class T> struct variant_size<volatile T>;
  14. // template <class T> struct variant_size<const volatile T>;
  15. // template <class T> constexpr size_t variant_size_v
  16. // = variant_size<T>::value;
  17. #include <memory>
  18. #include <type_traits>
  19. #include <variant>
  20. #include "test_macros.h"
  21. template <class V, size_t E> void test() {
  22. static_assert(std::variant_size<V>::value == E, "");
  23. static_assert(std::variant_size<const V>::value == E, "");
  24. static_assert(std::variant_size<volatile V>::value == E, "");
  25. static_assert(std::variant_size<const volatile V>::value == E, "");
  26. static_assert(std::variant_size_v<V> == E, "");
  27. static_assert(std::variant_size_v<const V> == E, "");
  28. static_assert(std::variant_size_v<volatile V> == E, "");
  29. static_assert(std::variant_size_v<const volatile V> == E, "");
  30. static_assert(std::is_base_of<std::integral_constant<std::size_t, E>,
  31. std::variant_size<V>>::value,
  32. "");
  33. };
  34. int main(int, char**) {
  35. test<std::variant<>, 0>();
  36. test<std::variant<void *>, 1>();
  37. test<std::variant<long, long, void *, double>, 4>();
  38. return 0;
  39. }