寻找一种 C++11/14 语法,我可以在其中为我的二维数组的内部数组的每个单元格分配一个计算值(外部数组是那些内部线的数组):
void foo(std::array<std::array<char, NCOLS>, NROWS>& other_array) {
float value = 42.0;
std::array<std::array<float, other_array[0].size()>,
other_array.size()> new_array; // HOW DO I ASSIGN value to all elements?
// .../...
}
最佳答案
for (auto& row : new_array)
std::fill(row.begin(), row.end(), value);
关于c++ - 用计算值初始化 2D std::array 的最快和最简洁的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31213088/