C++ 数组库 - tuple_size() 函数



描述

C++ 函数std::tuple_size(std::array) 返回容器中存在的元素总数。

声明

以下是来自 std::array 头文件的 std::tuple_size(std::array) 函数的声明。

template< class T, size_t N >
class tuple_size< array<T, N> > :
   public integral_constant≶size_t, N>
{ };

参数

T - 获取元组大小的类型。

示例

以下示例演示了 std::tuple_size(std::array) 函数的使用。

#include <iostream>
#include <array>

using namespace std;

int main(void) {

   typedef array<int, 4> arr;

   cout << "Size = " << tuple_size<arr>::value << endl;

   return 0;
}

让我们编译并运行上述程序,这将产生以下结果:

Size = 4
array.htm
广告

© . All rights reserved.