是否可以通过 std::tuple_cat 在 for 循环中组合元组,改变之前计算的元组?
我想按如下方式使用函数:
std::tuple<int> data;
for(int i = 0; i < max; i++)
{
/* ... some function which changes the value of data ... */
auto temp = std::tuple_cat(temp, data); // Add the new data to the previous tuple
}
它在逻辑上是不可编译的(temp 在初始化之前不能使用)。我该如何解决这个问题?
最佳答案
按照您在 for
循环中的逻辑,元组的大小预计会发生变化。
这是不可能的。因为元组的大小应该是编译时常量,所以不能使用相同的变量作为不同大小的元组。
关于c++ - 在循环中组合元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48504762/