寻找C ++ 11/14语法,我可以为我的2D数组分配计算值到内部数组的每个单元格(外部数组是这些内部行的数组):
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?
// .../...
}
答案 0 :(得分:1)
for (auto& row : new_array)
std::fill(row.begin(), row.end(), value);