xref: /llvm-project/libcxx/test/std/utilities/variant/variant.helpers/variant_size.pass.cpp (revision 7fc6a55688c816f5fc1a5481ae7af25be7500356)
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 
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 
12 // <variant>
13 
14 // template <class T> struct variant_size; // undefined
15 // template <class T> struct variant_size<const T>;
16 // template <class T> struct variant_size<volatile T>;
17 // template <class T> struct variant_size<const volatile T>;
18 // template <class T> constexpr size_t variant_size_v
19 //     = variant_size<T>::value;
20 
21 #include <memory>
22 #include <type_traits>
23 #include <variant>
24 
25 #include "test_macros.h"
26 
27 template <class V, size_t E> void test() {
28   static_assert(std::variant_size<V>::value == E, "");
29   static_assert(std::variant_size<const V>::value == E, "");
30   static_assert(std::variant_size<volatile V>::value == E, "");
31   static_assert(std::variant_size<const volatile V>::value == E, "");
32   static_assert(std::variant_size_v<V> == E, "");
33   static_assert(std::variant_size_v<const V> == E, "");
34   static_assert(std::variant_size_v<volatile V> == E, "");
35   static_assert(std::variant_size_v<const volatile V> == E, "");
36   static_assert(std::is_base_of<std::integral_constant<std::size_t, E>,
37                                 std::variant_size<V>>::value,
38                 "");
39 };
40 
41 int main(int, char**) {
42   test<std::variant<>, 0>();
43   test<std::variant<void *>, 1>();
44   test<std::variant<long, long, void *, double>, 4>();
45 
46   return 0;
47 }
48