std::tuple_size<std::tuple>
STD::元组[医]大小<std::tuple>
Defined in header | | |
---|---|---|
template< class T > class tuple_size; /*undefined*/ | (1) | (since C++11) |
template< class... Types > class tuple_size< std::tuple<Types...> > : public std::integral_constant<std::size_t, sizeof...(Types)> { }; | (2) | (since C++11) |
Defined in header <tuple> | | |
Defined in header <array> Defined in header <utility> | | (since C++17)(since C++17) |
template< class T > class tuple_size<const T> : public std::integral_constant<std::size_t, tuple_size<T>::value> { }; | (3) | (since C++11) |
template< class T > class tuple_size< volatile T > : public std::integral_constant<std::size_t, tuple_size<T>::value> { }; | (4) | (since C++11) |
template< class T > class tuple_size< const volatile T > : public std::integral_constant<std::size_t, tuple_size<T>::value> { }; | (5) | (since C++11) |
以编译时常量表达式的形式提供对元组中元素数的访问。
除了通过包含<tuple>标头时,模板%283-5%29可用。<array>或<utility>包括在内。
所有的专门化std::tuple_size满足感UnaryTypeTrait带着基本特征std::integral_constant<std::size_t, N>对一些人来说N...
The cv-T templates (3-5) are SFINAE-friendly: if std::tuple_size | (since C++17) |
---|
辅助变量模板
template< class T > inline constexpr std::size_t tuple_size_v = tuple_size | | (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> |
例
二次
#include <iostream>
#include <tuple>
template <class T>
void test(T t)
{
int a[std::tuple_size<T>::value]; // can be used at compile time
std::cout << std::tuple_size<T>::value << '\n'; // or at run time
}
int main()
{
test(std::make_tuple(1, 2, 3.14)
}
二次
产出:
二次
3
二次
另见
std::tuple_size | obtains the size of an array (class template specialization) |
---|---|
std::tuple_size<std::pair> (C++11) | obtains the size of a pair (class template specialization) |
std::get(std::tuple) | tuple accesses specified element (function template) |
tuple_element | obtains the type of the specified element (class template specialization) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。