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 template <class V, size_t E> void test() { 26 static_assert(std::variant_size<V>::value == E, ""); 27 static_assert(std::variant_size<const V>::value == E, ""); 28 static_assert(std::variant_size<volatile V>::value == E, ""); 29 static_assert(std::variant_size<const volatile V>::value == E, ""); 30 static_assert(std::variant_size_v<V> == E, ""); 31 static_assert(std::variant_size_v<const V> == E, ""); 32 static_assert(std::variant_size_v<volatile V> == E, ""); 33 static_assert(std::variant_size_v<const volatile V> == E, ""); 34 static_assert(std::is_base_of<std::integral_constant<std::size_t, E>, 35 std::variant_size<V>>::value, 36 ""); 37 }; 38 39 int main(int, char**) { 40 test<std::variant<>, 0>(); 41 test<std::variant<void *>, 1>(); 42 test<std::variant<long, long, void *, double>, 4>(); 43 44 return 0; 45 } 46