Why is non-const std::array::operator[] not constexpr?
I'm trying to fill a 2D array on compile time with a given function. Here is my code: 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 It works just fine, table.data is properly populated at compile time. However, if I change plain 2D array int[H][W] with std::array<std::array<int, H>, W> , I