Combine two or more arrays of different size to one array at compiletime

Viewed 1880

I was not able to find an answer on how to combine two or more arrays at compiletime in modern c++.

#include <array>
#include <cstdint>

const std::array<std::uint8_t, 1> one_elem = {1};
const std::array<std::uint8_t, 2> two_elem = {2, 3};
const std::array<std::uint8_t, 3> all = {one_elem, two_elem}; 
// expected: all == {1, 2, 3}

I would be glad with anything that is somewhat easy to read, e.g.

std::uint8_t one_elem[] = {1};
std::uint8_t two_elem[] = {2, 3};
std::uint8_t all[] = {one_elem, two_elem}; // cannot be that hard

Is there a way? What can I do to get this solved?

2 Answers
Related