It is possible to create a std::array using initialization lists in several ways. However, GCC 4.6.1 may encounter errors when attempting this.
The syntax for creating a std::array using initialization lists is:
std::array array = { { value1, value2, ..., valueN } };
where T is the array's element type, size is the array's size, and value1 to valueN are the array's initial values.
std::array is an aggregate struct, which allows it to be aggregate-initialized. To aggregate-initialize the array inside the struct, use an additional set of curly braces:
std::array<:string> strings = {{ "a", "b" }};
This syntax avoids the constructor that takes an initializer list, which may cause problems in GCC 4.6.1.
The C 11 standard suggests that the extra curly braces can be elided in aggregate initialization. Therefore, the inability of GCC 4.6.1 to compile initialization lists for std::array without the extra braces is likely a compiler bug.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3