std::array of std::array 是否有连续内存?

Does std::array of std::array have contiguous memory?

看来,我发现了如何在两行代码中轻松获得具有连续内存的普通二维数组:

template<int N, int M>
using Array2D = array<array<int, M>, N>;

让我们解决Array2D(一点c++17)中交换最小值和最大值的简单任务:

template<int N, int M>
void printArray2D(const Array2D<N, M> &arr);

int main() {
    const int N = 5;
    const int M = 5;
    Array2D<N, M> arr;

    // random init of Array2D 
    generate(arr.front().begin(), arr.back().end(), []()->int {
                                                        return rand() % 100;
                                                    });

    printArray2D(arr);

    auto[a, b] = minmax_element(arr.front().begin(), arr.back().end());

    cout << "Swap minimum and maximum: " << *a << " " << *b << endl << endl;

    iter_swap(a, b);
    printArray2D(arr);

    return 0;
}

template<int N, int M>
void printArray2D(const Array2D<N, M> &arr) {
    for (const auto &row : arr) {
        for (const auto &elem : row) {
            cout << std::setw(3) << elem;
        }
        cout << endl;
        cout << endl;
    }
}

我在 Visual Studio 2017 年获得了下一个成绩:

 41 67 34  0 69

 24 78 58 62 64

  5 45 81 27 61

 91 95 42 27 36

 91  4  2 53 92

Swap minimum and maximum: 0 95

 41 67 34 95 69

 24 78 58 62 64

  5 45 81 27 61

 91  0 42 27 36

 91  4  2 53 92

优点:

缺点:

问题:

根据标准,内存应该是连续的。 26.3.7.1 [array.overview] 段落指出(强调我的):

The header defines a class template for storing fixed-size sequences of objects. An array is a contiguous container. An instance of array stores N elements of type T, so that size() == N is an invariant.

更新: 看来实现 可能 包括填充。 这些 SO 帖子中有关该主题的更多信息:
Is the size of std::array defined by standard?
特别是这个答案:
Is the data in nested std::arrays guaranteed to be contiguous?