gpt4 book ai didi

c++ - 数组和类聚合类型的统一初始化

转载 作者:行者123 更新时间:2023-11-30 02:50:03 24 4
gpt4 key购买 nike

n3526 建议稍微放宽从聚合初始化中删除大括号的规则,以使数组和类聚合的初始化更加统一。

它将允许编译以下代码:

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};

然后它说:

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.

有谁知道在使这种语法成为可能方面是否有任何进展,如果没有,不允许它的原因是什么?

最佳答案

Evolution 工作组在布里斯托尔 session 上对这篇论文进行了审议,得出的结论是当前的限制是经过深思熟虑的。我不是这次讨论的一部分,因此对细节了解不多。似乎也有人指出,即使没有给出示例,即使所陈述的提案也可能会更改现有的有效代码。据我所知,这个提议没有被采纳:

No recommendation to move forward, considered NAD.

关于c++ - 数组和类聚合类型的统一初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20768540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com