以静态大小的数组作为参数的通用 lambda
Generic lambdas with statically sized arrays as arguments
以下通用(多态)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.
以下通用(多态)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-seqoptand the type of the identifier in the declaration
T D1
is “derived-declarator-type-listT
”, then the type of the identifier ofD
is an array type; if the type of the identifier ofD
contains theauto
type-specifier, the program is ill-formed.