我需要一种从另一个元组生成新元组的方法。
std::string f1(int a)
{
std::string b = "hello";
return b;
}
float f2(std::string a)
{
float b = 2.5f;
return b;
}
int f3(float a)
{
int b = 4;
return b;
}
int main()
{
auto t1 = std::make_tuple(1, "a", 1.5f);
//New tuple ---> std::tuple<std::string, float, int>(f1(1), f2("a"), f3(1.5));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这只是我想做的一个最小的例子。有没有办法在 C++20 中做到这一点,也许使用std::tuple_cat
?
我刚刚遇到这个 C 问题,代码如下:
int fun();
int main()
{
for (fun(); fun(); fun())
printf("%d\n", fun());
return 0;
}
int fun()
{
int static n = 10;
return n--;
}
Run Code Online (Sandbox Code Playgroud)
我期望for
循环计算为for(10;9;8)
并printf
打印 7 (因为我们将使用fun()
?进行调用n = 7
),但它打印了8
。为什么会出现这种情况?