If I initialize a std::array as follows, the compiler gives me a warning about missing braces
std::array<int, 4> a = {1, 2, 3, 4};
This fixes the problem:
std::array<int, 4> a = {{1, 2, 3, 4}};
This is the warning message:
missing braces around initializer for 'std::array<int, 4u>::value_type [4] {aka int [4]}' [-Wmissing-braces]
Is this just a bug in my version of gcc, or is it done intentionally? If so, why?
std::array
is an aggregate. I think they might be making it work with one set in the future, however. – Coercivestruct S {int i; int j;};
and initialize it usingS s = {5, 6};
? That's aggregate initialization.std::array
contains a built-in array, which can be initialized via an initializer list, which is what the inner set is. The outer set is for aggregate initialization. – Coercivestd::array<>
is an aggreate also, the first brace initializes thestd::arrat<>
, and the second initializes the inner C-array. – Flatt