In order to initialize a std::array
with some values, you need to use this approach:
std::array<int,3> an_array{{3,4,5}};
I am aware of the reason that we need two curly braces (one for std::array
and the the other for the inner c-style array
).
My question: Why, by standard, std::array
does not contain an initializer-list constructor that directly initialize the inner c-style array
? Is not more eyes-friendly to be initialized as:
std::array<int,3> an_array{3,4,5};
Edit:
This information is from http://en.cppreference.com/w/cpp/container/array. I thought my compiler is allowing the second version directly as non-standard extension. Now, I am not even sure what is the standard exactly about this case.
// construction uses aggregate initialization
std::array<int, 3> a1{ {1, 2, 3} };
// double-braces required in C++11 (not in C++14)