std::variant_size
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) |
以编译时常量表达式的形式提供对可能的cv限定变量中的替代方案的访问。
正式的,
2%29UnaryTypeTrait
具有基本特征的需求std::integral_constant<std::size_t, sizeof...(Types)>
3%29UnaryTypeTrait
具有基本特征的需求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) |
---|
继承自STD:积分[医]常量
成员常数
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> |
注记
所有的专门化std::variant_size
满足感UnaryTypeTrait
带着基本特征std::integral_constant<std::size_t, N>
对一些人来说N
...
例
另见
variant_alternativevariant_alternative_t (C++17) | obtains the type of the alternative specified by its index, at compile time (class template) (alias template) |
---|---|
tuple_size | obtains the size of tuple at compile time (class template specialization) |
? cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com