Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何获取元组中的成员数_C++_Std - Fatal编程技术网

C++ 如何获取元组中的成员数

C++ 如何获取元组中的成员数,c++,std,C++,Std,如何获取元组中元素的数量。这样我就可以做下面的事情了 for(int i=0;i<tuple.count();++i) cout << std::get<i>(tuple) << endl; for(inti=0;i您可以使用tuple\u size了解tuple的大小 int size = tuple_size<decltype(mytuple)>::value; // size of tuple int size=tuple\

如何获取元组中元素的数量。这样我就可以做下面的事情了

for(int i=0;i<tuple.count();++i)
    cout << std::get<i>(tuple) << endl;

for(inti=0;i您可以使用
tuple\u size
了解tuple的大小

int size = tuple_size<decltype(mytuple)>::value; // size of tuple
int size=tuple\u size::value;//tuple的大小
更新:

为了使用元组的值,需要在编译时知道它,而不是在运行时。 因此不能直接使用循环


而不是你可以对每个索引值使用
get(mytuple),get(mytuple),get(mytuple)

也许会帮助你
std::apply([](const auto&…e){(std::在提问之前请先阅读文档。但是
std::get(tuple)中的
i
是一个模板参数。因此需要在编译时知道它。因此,您不能使用
for
循环进行迭代。