以下通用(多态)lambda 是否合法 C++14?
auto f = [](auto x[3]) {
x[0];
x[1];
// etc.
};
GCC 和 Clang 4 接受该代码,但 Visual Studio 2017 不接受。合法吗?
error C3318: 'auto [3]': an array cannot have an element type that contains 'auto'
这是非法的。
[dcl.数组]/1 http://eel.is/c++draft/dcl.array#1.sentence-1,强调我的:
在声明 T D 中,其中 D 的形式为
D1 [ constant-expressionopt ] attribute-specifier-seqopt
以及声明中标识符的类型T D1
is “派生声明符类型列表 T
”,那么标识符的类型D
是数组类型;如果标识符的类型D
包含auto
类型说明符,该程序格式错误。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)