std::tuple_size(std::array)
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   在标头  <array> 定义
  | 
||
|   template< class T, std::size_t N > struct tuple_size< std::array<T, N> > :  | 
(C++11 起) | |
提供作为编译时常量表达式访问 std::array 中元素数量的方法。
继承自 std::integral_constant
成员常量
|    value [静态]  | 
   N , array 中的元素数  (公开静态成员常量)  | 
成员函数
|    operator std::size_t  | 
   将对象转换到 std::size_t,返回 value   (公开成员函数)  | 
|    operator() (C++14)  | 
   返回 value   (公开成员函数)  | 
成员类型
| 类型 | 定义 | 
  value_type
 | 
std::size_t | 
  type
 | 
std::integral_constant<std::size_t, value> | 
示例
运行此代码
#include <iostream> #include <array> template<class T> void test(T t) { int a[std::tuple_size<T>::value]; // 能用于编译时 std::cout << std::tuple_size<T>::value << '\n'; } int main() { std::array<float, 3> arr; test(arr); }
输出:
3
参阅
| 结构化绑定 (C++17) | 绑定指定的名字到初始化器的子对象或元组元素 | 
|    (C++11)  | 
  在编译时获得 tuple 的大小 (类模板特化)  |