I have a class which can be templated based on a single size parameter. I want to have a constructor which accepts a variable amount of std::array
based on the template size parameter. So if the class is templated to one. It should accept a single array. If templated to two it should accept two etc.
This is what I came up with but obviously it doesn't work:
template<std::size_t V>
class Test
{
public:
/* Constructors. */
Test() {}
template <std::array<int, 3> ...Args, typename = typename std::enable_if<V == sizeof...(Args), void>::type>
Test(std::array<int, 3>&&... args)
{
}
};
int main()
{
auto t = Test<1>({ 1, 2, 3 });
auto t2 = Test<2>(
{ 1, 2, 3 },
{ 4, 5, 6 }
);
}
The error I recieve is:
error C2993: 'std::array<int,3>': illegal type for non-type template parameter 'Args'
note: see reference to class template instantiation 'Test<V>' being compiled
error C3543: 'std::array<int,3> &&': does not contain a parameter pack
error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'Test<1>'
note: No constructor could take the source type, or constructor overload resolution was ambiguous
error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'Test<2>'
note: No constructor could take the source type, or constructor overload resolution was ambiguous
Any help is appreciated.