I have an array of arrays and want to fill them up with some value.
This doesn't work:
std::array<std::array<int, 5>, 4> list;
for (auto item : list) {
std::fill(item.begin(), item.end(), 65);
}
However, this does:
for (int i = 0; i < 4; i++) {
std::fill(list[i].begin(), list[i].end(), 65);
}
What am I missing? Looking at the debugger, the first example does nothing on list. The type of item is std::array<int, 5>, as expected, so I'm not sure what went wrong.
for (auto item : list) {=>for (auto& item : list) {autodoes not deduce references, soitemis a copy of the element. Change toauto& item...