I am using std::array (N is a fixed template-variable).
#include
template
struct A{
size_t fun
You can enforce this by using parameter pack, but with a bit different syntax:
#include
template
struct A{
template
size_t function(T&&... nums)
{
static_assert(sizeof...(nums) == N, "Wrong number of arguments");
std::array arr = { std::forward(nums)... };
return arr[N-1];
}
};
int main(){
A<5> a;
a.function(1,2,3,4,5); // OK
a.function(1,2,4,5); // Compile-time error
}
But, I think there is no good way to enforce that in compile time. I would just use assert(il.size() == N) in production code to check size of initializer list.