Store multiple std arrays of variable size

I have different std::arrays with variable sizes, e.g.

std::array<int, 5> array_one;
std::array<int, 8> array_two;
std::array<int, 2> array_three;

The primary type is always the same (int in this example).

Now I have to iterate over all those arrays and in order to do that with as little code as possible, I thought I would store them in e.g. one array and use it to access each array individually.

Pseudocode:

std::array array_wrapper = { array_one, array_two, array_three };

But that will not work as each array has a different size.

Is there any storage type I can use to “collect” all arrays to iterate over them individually afterwards?

Answer

In case you just need to iterate, not to store arrays together, use std::span

std::span<int> span[] = {array_one, array_two, array_three};

You may also flatten the views with std::views::join

for(int &i : span | std::views::join)
{
    ...
}

If arrays are constant, then

std::span<int const> span[] = {array_one, array_two, array_three};
for(int const i : span | std::views::join)
{
    ...
}