且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++ 20从带括号的值列表初始化聚合,不支持内部数组

更新时间:2023-11-09 08:57:52

p0960在r1和r2之间更改:

p0960 changed between r1 and r2:

r2:此修订将心理模型从原始的将文字重写为括号列表更改为 ,就像调用了带有适当的mem-initializers的综合显式构造函数一样。 1 。即使在相应的括号列表语法中禁止缩小转换的情况下,也具有允许在括号列表中缩小转换的效果。它还阐明了不延长引用临时对象的临时寿命,不存在大括号省略和不存在对参数进行明确定义的求值顺序。

r2: This revision changes the mental model from the original "literal rewrite to a braced list" to "as if a synthesized, explicit constructor with appropriate mem-initializers was called"1. This has the effect of allowing narrowing conversions in the parenthesized list, even when narrowing conversions would be forbidden in the corresponding braced list syntax. It also clarifies the non-extension of temporary lifetimes of temporaries bound to references, the absence of brace elision, and the absence of a well-defined order of evaluation of the arguments.

进行此更改的原因可以在已更改的p0960设计原理中找到:

The reason why this change was made can be found in the changed design principles for p0960:


r1:括号内的初始化和括号内的初始化

r1: Parenthesized initialization and braced-initialization should be as similar as possible.

r2:
括号化的初始化和支撑初始化应尽可能相似,但必须与众不同,以与现有的一致括号列表和括号列表的心理模型。
强调我的

为什么p0960没有采用更简单的方法()初始化,更像{}?

当决定与现有心理模型保持一致时 1 已被采用,不允许括号删除似乎是 only 方法。

When the decision to go for conformance with the existing mental models 1 had been taken, not allowing brace elision seems like the only approach.