小编bha*_*438的帖子

有没有办法从已经存在的元组创建新的元组?

我需要一种从另一个元组生成新元组的方法。

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++ c++17 c++20

1
推荐指数
1
解决办法
314
查看次数

为什么下面的代码打印8,5,2而不是7,4,1?

我刚刚遇到这个 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。为什么会出现这种情况?

c for-loop decrement postfix-operator

1
推荐指数
1
解决办法
112
查看次数

标签 统计

c ×1

c++ ×1

c++17 ×1

c++20 ×1

decrement ×1

for-loop ×1

postfix-operator ×1