Before looking at how we could define such a structure, let's consider several test cases for it. The following snippet shows all the functionality that was requested:
int main(){ // element access array2d<int, 2, 3> a {1, 2, 3, 4, 5, 6}; for (size_t i = 0; i < a.size(1); ++i) for (size_t j = 0; j < a.size(2); ++j) a(i, j) *= 2; // iterating std::copy(std::begin(a), std::end(a), std::ostream_iterator<int>(std::cout, " ")); // filling array2d<int, 2, 3> b; b.fill(1); // swapping a.swap(b); // moving array2d<int, 2, 3> c(std::move(b));}
Note that for element access, we are using operator(), such as in a(i,j), and not operator[], such as in a[i][j], because only the former can take multiple arguments ...