gpt4 book ai didi

c++ - 以静态大小的数组作为参数的通用 lambda

转载 作者:可可西里 更新时间:2023-11-01 18:27:52 26 4
gpt4 key购买 nike

以下通用(多态)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.array]/1 ,强调我的:

In a declaration T D where D has the form

D1 [ constant-expressionopt ] attribute-specifier-seqopt

and the type of the identifier in the declaration T D1 is “derived-declarator-type-list T”, then the type of the identifier of D is an array type; if the type of the identifier of D contains the auto type-specifier, the program is ill-formed.

关于c++ - 以静态大小的数组作为参数的通用 lambda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45902923/

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