Can we omit the double-braces for std::array in C++14?

前端 未结 1 1594
野性不改
野性不改 2020-12-01 23:46

I\'m reading through the draft standard for C++14 right now, and perhaps my legalese is a bit rusty, but I can\'t find any mention of allowing initializations like the follo

相关标签:
1条回答
  • 2020-12-02 00:16

    Actually you can write the following in C++11 also:

    std::array<int, 3> arr{1,2,3};
    

    It is completely valid syntax.

    What is not allowed in C++11 though is something like this case (see that topic; I don't want to write this here again, it is a long post). So if you ask that then, yes, we can omit the extra braces in C++14. This is the proposal:

    • Uniform initialization for arrays and class aggregate types

    • The introduction says

      This document proposes a slight relaxation of the rules for eliding braces from aggregate initialization in order to make initialization of arrays and class aggregates more uniform. This change is required in order to support class aggregate types with a single member subaggregate that behave similarly to their array counterparts (i.e. std::array).

    Hope that helps.

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