我正在尝试使用给定的函数在编译时填充2D数组.这是我的代码:
template<int H, int W>
struct Table
{
int data[H][W];
//std::array<std::array<int, H>, W> data; // This does not work
constexpr Table() : data{}
{
for (int i = 0; i < H; ++i)
for (int j = 0; j < W; ++j)
data[i][j] = i * 10 + j; // This does not work with std::array
}
};
constexpr Table<3, 5> table; // I have table.data properly populated at compile time
Run Code Online (Sandbox Code Playgroud)
它运行得很好,table.data在编译时正确填充.
然而,如果我改变普通2D阵列int[H][W]与std::array<std::array<int, H>, W> …