Defined in header <variant> | ||
---|---|---|
template <class T> struct variant_size; /* undefined */ | (1) | (since C++17) |
template <class... Types> struct variant_size<std::variant<Types...>> : std::integral_constant<std::size_t, sizeof...(Types)> { }; | (2) | (since C++17) |
template <class T> class variant_size<const T>; template <class T> class variant_size<volatile T>; template <class T> class variant_size<const volatile T>; | (3) | (since C++17) |
Provides access to the number of alternatives in a possibly cv-qualified variant as a compile-time constant expression.
Formally,
UnaryTypeTrait
requirements with a BaseCharacteristic of std::integral_constant<std::size_t, sizeof...(Types)>
UnaryTypeTrait
requirements with a BaseCharacteristic of std::integral_constant<std::size_t, variant_size<T>>
template <class T> inline constexpr std::size_t variant_size_v = std::variant_size<T>::value; | (since C++17) |
value
[static] | sizeof...(Types) (public static member constant) |
operator std::size_t | converts the object to std::size_t , returns value (public member function) |
operator()
(C++14) | returns value (public member function) |
Type | Definition |
---|---|
value_type | std::size_t |
type | std::integral_constant<std::size_t, value> |
All specializations of std::variant_size
satisfy UnaryTypeTrait
with BaseCharacteristic std::integral_constant<std::size_t, N>
for some N
.
(C++17) | obtains the type of the alternative specified by its index, at compile time (class template) (alias template) |
obtains the size of tuple at compile time (class template specialization) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/variant/variant_size