Given the two-dimensional array
std::array<std::array<int, 2>, 3> m = {{ {1, 2}, {3, 4}, {5, 6} }};
I am looking for the sum of all its elements - in this case, 21. Had the array been one-dimensional, I could've written
auto sum = std::accumulate(m.begin(), m.end(), 0);
but for my two-dimensional array, this fails with the rather understandable error
no match for 'operator+' (operand types are 'int' and 'std::array<int, 2ul>')
How can I elegantly compute this sum for my 2D array (avoiding for-loops, preferring STL-algorithms)?
Can it be done with a one-liner like for the one-dimensional case, or does it become more complex?