2

I am using a nested std::array, and wonder if it is possible to use memcpy on it in order to copy the content of one array to the other as sketched below:

std::array<std::array<int, 5>, 5> arr;
std::array<std::array<int, 5>, 5> arr2;
memcpy(&arr[0], &arr2[0], sizeof(int) * 25);

Since C++17, a C++ array is a ContiguousContainer; however, I think that the question if padding bytes can be placed at the end of an array (which is basically inside the memory chunk in a nested array) are unaffected by this property.

Is the data in std::array<std::array<T,N>, M> guaranteed to be contiguous? Or does the answer to this pre-c++17 question still hold?

mutableVoid
  • 1,284
  • 2
  • 11
  • 29

0 Answers0