简体   繁体   中英

Uniform initialization for arrays and class aggregate types

n3526 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.

It would allow the following code to compile:

struct S {
    int x[2][2];
};

struct A {
    S s;
};

// Then the following declarations are all equivalent

A a1 = {{{{1, 2}, {3, 4}}}};
A a2 = {{{1, 2}, {3, 4}}};
A a3 = {{1, 2}, {3, 4}};
A a4 = {1, 2, 3, 4};

It then says:

Allowing brace-elision on aggregates with more than one member was considered and rejected as it seems likely to cause difficulties parsing programs that were already well-formed.

Does anyone know if there's any progress on making this syntax possible, and if not, what would be the reason for not allowing it?

The paper was considered by the Evolution working group at the Bristol meeting and the conclusion was that the current constraints were deliberate. I wasn't part of this discussion and, thus, don't know much about the details. It seems it was also noted that even the proposal as stated may change existing valid code although there was no example given. As far as I can see, the proposal isn't pursued:

No recommendation to move forward, considered NAD.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM