I am using std::array
(N is a fixed template-variable).
#include
template
struct A{
size_t fun
Simple answer: You cannot.
When initializing std::array
with a list, it is doing an aggregate initialization
, and it is explained here when the list size is less than the number of member:
It is simply a legal and acceptable behavior to provide less than the size list, so compiler will not complain anything. Your code:
A<5> a;
a.function({{1,2,3}}));
is equivalent to:
A<5> a;
a.function({{1,2,3,0,0}}));
to compiler. Your best bet is runtime error (which may not be as you wished).