Is it possible to pass data as initializer_list to std::array of structures?

前端 未结 1 750
慢半拍i
慢半拍i 2021-01-26 08:14

I have the following code. Basically I want to initialize a std::array of non-POD structs using aggregate initialization syntax. Both g++ 4.6 and 4.7 (latest weekly snapshot) fa

相关标签:
1条回答
  • 2021-01-26 08:52

    std::array is an aggregate containing an array, so you need an extra pair of braces to initialise it from a regular array:

    {1,2}               // TheClass
    {{1,2},{2,3}}       // TheClass[2]
    {{{1,2},{2,3}}}     // std::array<TheClass,2>
    {{{{1,2},{2,3}}}}   // OtherClass<2>
    

    However, it seems that older versions of GCC still stuggle with this: 4.5.1 rejects it, while 4.6.1 accepts it.

    0 讨论(0)
提交回复
热议问题