Unless I am mistaken, it should be possible to create a std:array in these ways:
std::array<std::string, 2> strings = { "a", "b" };
std::array<std::string, 2> strings({ "a", "b" });
And yet, using GCC 4.6.1 I am unable to get any of these to work. The compiler simply says:
expected primary-expression before ',' token
and yet initialization lists work just fine with std::vector. So which is it? Am I mistaken to think std::array should accept initialization lists, or has the GNU Standard C++ Library team goofed?
std::arrayis funny. It is defined basically like this:It is a struct which contains an array. It does not have a constructor that takes an initializer list. But
std::arrayis an aggregate by the rules of C++11, and therefore it can be created by aggregate initialization. To aggregate initialize the array inside the struct, you need a second set of curly braces:Note that the standard does suggest that the extra braces can be elided in this case. So it likely is a GCC bug.