具有静态大小数组作为参数的通用lambdas

时间:2017-08-27 08:10:09

标签: c++ c++14 generic-lambda

以下通用(多态)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'

1 个答案:

答案 0 :(得分:9)

这是非法的。

[dcl.array]/1,强调我的:

  

在声明T D中,D的格式为

D1 [ constant-expressionopt ] attribute-specifier-seqopt
     

并且声明T D1中的标识符类型是“ derived-declarator-type-list T”,然后是{{1的标识符的类型是一个数组类型; 如果D的标识符类型包含D 类型说明符,则该程序格式错误。