emplace_back std::vector<std::array>不起作用



我想知道这样简单的程序不能用gcc、clang和msvc:编译

#include <array>
#include <vector>
int main()
{
std::vector<std::array<int, 3>> v;
v.emplace_back( 1, 2, 3 );
return 0;
}

为什么std::数组不能从值序列中构造?编写具有可变通用引用的自定义ctor以有效地从值构造std::数组看起来非常容易。

我认为如果std::array被认为是POD结构,那就太好了。

您试图将整数放入std::vector,而不是您定义的std::array<int, 3>。目前还不清楚v.emplace_back( 1, 2, 3 );的含义。它是指std::array<int, 3>{ 1, 2, 3 }作为向量中的一项,还是指{ std::array<int, 3>{ 1, 1, 1 }, std::array<int, 3>{ 2, 2, 2 }, std::array<int, 3>{ 3, 3, 3 } }或其他什么?

最新更新