Is the underlying bit representation for an std::array<T,N> v and a T u[N] the same?
In other words, is it safe to copy N*sizeof(T) bytes from one to the other? (Either through reinterpret_cast or memcpy.)
Edit:
For clarification, the emphasis is on same bit representation and reinterpret_cast.
For example, let's suppose I have these two classes over some trivially copyable type T, for some N:
struct VecNew {
std::array<T,N> v;
};
struct VecOld {
T v[N];
};
And there is the legacy function
T foo(const VecOld& x);
If the representations are the same, then this call is safe and avoids copying:
VecNew x;
foo(reinterpret_cast<const VecOld&>(x));
data/&array_name[0]or using the name of the "array" itself?reinterpret_cast, because of strict aliasing.reinterpret_cast-ing. That's somewhat different...VecNewby adding new field for example and enjoy debugging. No, thanks.