std::array
is an aggregate. It has only one data member - an array of the specified type of the std::array
specialization. According to the C++ Standard. (8.5.1 Aggregates)
2 When an aggregate is initialized by an initializer list, as
specified in 8.5.4, the elements of the initializer list are taken as
initializers for the members of the aggregate, in increasing subscript
or member order
So this record
std::array<std::pair<int, int>, 2> ids = { { 0, 1 }, { 1, 2 } };
has more initializers then there are data members in std::array.
The data member of std::array
is in turn an aggregate. You have to provide for it an initializer list.
So the record will look like
std::array<std::pair<int, int>, 2> ids = { { { 0, 1 }, { 1, 2 } } };
For it would be more clear you can imagine the initialization the following way
std::array<std::pair<int, int>, 2> ids = { /* an initializer for data member of the array */ };
As the data member is aggregate then you have to write
std::array<std::pair<int, int>, 2> ids = { { /* initializers for the aggregate data member*/ } };
And at last
std::array<std::pair<int, int>, 2> ids = { { { 0, 1 }, { 1, 2 } } };
std::make_pair
. How does that work, without the extra pair of enclosing braces? – Grivet