The standard defines std::array as follows (N3337 for C ++ 11, but the parts quoted are identical in N4140):
ยง23.3.2.1 [array.overview] / 2
An array is a collection that can be initialized with syntax
array<T, N> a = { initializer-list };
and the population is defined as:
ยง8.5.1 [dcl.init.aggr] / 1
An aggregate is an array or class that does not contain user constructors, there are no private or protected non-static data elements, there is no base of classes and virtual functions.
Therefore, it cannot have a user-defined constructor that would be initializer_list .
In addition, C ++ 11 defines alignment of shapes only for the syntax T x = { a } :
ยง8.5.1 [dcl.init.aggr] / 11
In the form declaration
T x = { a };
Parenthesescan be dropped in the initializer list as follows. [...]
whereas C ++ 14 (N4140) cancels this requirement:
ยง8.5.1 [dcl.init.aggr] / 11
Braces can be discarded in the initializer list as follows. [...]
So, C ++ 14 and above is absolutely true:
std::array<int,3> an_array{3,4,5}
krzaq
source share