• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 // UNSUPPORTED: c++98, c++03, c++11, c++14
12 
13 // <variant>
14 
15 // template <class T> struct variant_size; // undefined
16 // template <class T> struct variant_size<const T>;
17 // template <class T> struct variant_size<volatile T>;
18 // template <class T> struct variant_size<const volatile T>;
19 // template <class T> constexpr size_t variant_size_v
20 //     = variant_size<T>::value;
21 
22 #include <memory>
23 #include <type_traits>
24 #include <variant>
25 
test()26 template <class V, size_t E> void test() {
27   static_assert(std::variant_size<V>::value == E, "");
28   static_assert(std::variant_size<const V>::value == E, "");
29   static_assert(std::variant_size<volatile V>::value == E, "");
30   static_assert(std::variant_size<const volatile V>::value == E, "");
31   static_assert(std::variant_size_v<V> == E, "");
32   static_assert(std::variant_size_v<const V> == E, "");
33   static_assert(std::variant_size_v<volatile V> == E, "");
34   static_assert(std::variant_size_v<const volatile V> == E, "");
35   static_assert(std::is_base_of<std::integral_constant<std::size_t, E>,
36                                 std::variant_size<V>>::value,
37                 "");
38 };
39 
main()40 int main() {
41   test<std::variant<>, 0>();
42   test<std::variant<void *>, 1>();
43   test<std::variant<long, long, void *, double>, 4>();
44 }
45