Suppose I have a compile-time constexpr array and a variadic class template with a set of non-type parameters of the same type as the elements of the array.
My objective is to instantiate the class template with the values from the array:
struct Container
{
int containee[3];
};
constexpr Container makeContainer();
template <int... Elements> class Foo;
Foo<makeContainer().containee[0],
makeContainer().containee[1],
makeContainer().containee[2]> foo;
The above code works well. However, I'm quite unhappy about having to manually index the array whenever I need to instantiate the Foo
template. I would like the compiler to do that for me automatically:
Foo<Magic(makeContainer().containee)> foo;
I did some RTFM at cppreference, but that didn't help. I'm aware of std::forward<>()
, but it cannot be applied to template argument lists.