gpt4 book ai didi

arrays - 如何将数组传递给 std::make_tuple?

转载 作者:行者123 更新时间:2023-12-01 11:22:02 25 4
gpt4 key购买 nike

这该怎么做:

#include <tuple>

std::tuple<double, int[2]> f()
{
return std::make_tuple(0., {1, 2});
}

int main()
{
f();
return 0;
}

could not convert 'std::make_tuple<{}>()' from 'std::tuple<>' to 'std::tuple'



编译器不知道该怎么做吗?

最佳答案

如果您需要使用“编译时向量”,请尝试 array .

#include <array>
// ...

std::tuple<double, std::array<int, 2>> f() {
return std::make_tuple(0., std::array<int, 2>{1, 2});
}

As an aggregate type, it can be initialized with aggregate-initialization given at most N initializers that are convertible to T.

关于arrays - 如何将数组传递给 std::make_tuple?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41102822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com