Frederick Gotham <
cauldwel...@gmail.com> wrote:
>
> In C++11, is std::array packed, unpadded, and castable? Can I do the following?
>
> void Func(array<char,4> &a, array<char,4> &b, array<char,4> &c)
> {
>
> }
>
> auto main(void) -> int
> {
> array<char,12> abc;
>
> Func(
> *reinterpret_cast<array<char,4> *>(&abc[0]),
> *reinterpret_cast<array<char,4> *>(&abc[4]),
> *reinterpret_cast<array<char,4> *>(&abc[8])
> );
> }
If you absolutely cannot change the signature of Func() above (eg. because
it's not code you are developing nor can affect), and you absolutely must
be able to "split" an existing std::array into several, then it's probably
not very kosher to do that according to the standard (although this is just
my hunch. I haven't read that part of the standard.)
If all that code is developed by you and you have a choice, then you can
simply create your own "array" class that explicitly offers that kind
of functionality. In modern C++ terminology it would be an an "array view".
Which, incidentally, is supported in C++20 directly IIRC, so if you can
afford using C++20 you can use the standard library implementation.
But creating your own should be quite easy.