To add to the accepted answer:
std::array<char, 2> a1{'a', 'b'}; std::array<char, 2> a2 = {'a', 'b'}; std::array<char, 2> a3{{'a', 'b'}}; std::array<char, 2> a4 = {{'a', 'b'}};
all work on GCC 4.6.3 (Xubuntu 12.01). However,
void f(std::array<char, 2> a) { }
this requires a double curly brace. The single brackets version results in the following error:
../src/main.cc: In function 'int main(int, char**)': ../src/main.cc:23:17: error: could not convert '{'a', 'b'}' from '<brace-enclosed initializer list>' to 'std::array<char, 2ul>'
I'm not sure which aspect of the output / conversion type does the work this way, or if this is a fad of the GCC implementation.
Joseph Sep 27 '12 at 8:11 2012-09-27 08:11
source share