Is there any syntax through which I can distribute a non-type parameter pack across the parameters of a parameter pack of templates, expecting non-type packs (of different sizes)? Since this is pretty confusing I believe that an example may help to clarify what I mean: https://godbolt.org/z/FaEGTV
template <typename T, int... I> struct Vec { };
struct A
{
template<template<typename, int...> typename... Container,
typename... Ts, int... Is>
A(Container<Ts,Is...>... );
};
A a(Vec<int, 0>{}, Vec<double, 0>{}); // ok
A b(Vec<int, 0, 1>{}, Vec<double, 0, 1>{}); // ok
A c(Vec<int, 0>{}, Vec<double, 0, 1>{}); // error
I want the line marked // error
to work with a syntax similar to what I have. Clearly it will work fine if I write a special constructor to handle this case. However I want this to work for any number of containers, without me having to spell it out explicitly for all possible cases. For example, if I have 2 containers a,b
, with index sets {0,1,2}
and {0,1,2,3}
the expansion should look like A(a[0],a[1],a[2], b[0],b[1],b[2],b[3])
.
I am aware that I could do this recursively, unpacking one container at a time, and delegating recursively to constructors expecting a sequence of only flat elements in the beginning. My question is whether this is feasible in a more elegant, efficient, and less verbose way.