#include <iostream>
#include <array>
template<unsigned... Is> struct seq{};
template<unsigned N, unsigned... Is>
struct gen_seq : gen_seq<N-1, N-1, Is...>{};
template<unsigned... Is>
struct gen_seq<0, Is...> : seq<Is...>{};
template<unsigned N1, unsigned... I1, unsigned N2, unsigned... I2>
// Expansion pack
constexpr std::array<int, N1+N2> concat(const std::array<int, N1>& a1, const std::array<int, N2>& a2, seq<I1...>, seq<I2...>){
return { a1[I1]..., a2[I2]... };
}
template<unsigned N1, unsigned N2>
// Initializer for the recursion
constexpr std::array<int, N1+N2> concat(const std::array<int, N1>& a1, const std::array<int, N2>& a2){
return concat(a1, a2, gen_seq<N1>{}, gen_seq<N2>{});
}
int main() {
constexpr std::array<int, 3> a1 = {1,2,3};
constexpr std::array<int, 2> a2 = {4,5};
constexpr std::array<int,5> res = concat(a1,a2);
for(int i=0; i<res.size(); ++i)
std::cout << res[i] << " "; // 1 2 3 4 5
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YXJyYXk+Cgp0ZW1wbGF0ZTx1bnNpZ25lZC4uLiBJcz4gc3RydWN0IHNlcXt9Owp0ZW1wbGF0ZTx1bnNpZ25lZCBOLCB1bnNpZ25lZC4uLiBJcz4Kc3RydWN0IGdlbl9zZXEgOiBnZW5fc2VxPE4tMSwgTi0xLCBJcy4uLj57fTsKdGVtcGxhdGU8dW5zaWduZWQuLi4gSXM+CnN0cnVjdCBnZW5fc2VxPDAsIElzLi4uPiA6IHNlcTxJcy4uLj57fTsKCnRlbXBsYXRlPHVuc2lnbmVkIE4xLCB1bnNpZ25lZC4uLiBJMSwgdW5zaWduZWQgTjIsIHVuc2lnbmVkLi4uIEkyPgovLyBFeHBhbnNpb24gcGFjawpjb25zdGV4cHIgc3RkOjphcnJheTxpbnQsIE4xK04yPiBjb25jYXQoY29uc3Qgc3RkOjphcnJheTxpbnQsIE4xPiYgYTEsIGNvbnN0IHN0ZDo6YXJyYXk8aW50LCBOMj4mIGEyLCBzZXE8ST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