是否(或将会)在 lambda 表达式中使用熟悉的模板语法?
Is (or will be) the use of familiar template syntax in lambda expressions allowed?
C++14 引入了通用 lambda。在浏览相关提案时,我发现 Faisal Vali、Herb Sutter 和 Dave Abrahams 提出的 N3418。
其中第 2.2 节的标题为:
2.2 Allow the use of familiar template syntax in lambda expressions
下面的代码示例包括这样的代码片段
[]<int N>(int (&a)[N]) {}
由于这些东西无法编译(使用 gcc、clang 和 Visual Studio),出现了一些问题:
- 这是一个实施问题吗?
- 是什么阻止了这部分被接受?
- 最终将通用 lambda 引入语言的提案是什么?
注意:我会对此发表评论,但没有这样的声誉。
如果我编译以下内容,你引用的精确结构就可以正常工作:
auto foo = []<int N>(int (&a)[N]) {};
与:
g++-4.9 -c foo.cpp -std=c++1y
但是,使用 g++-4.8
或 clang-3.6
都失败了。因此,我认为这是一个实施问题。但是,我对 C++14 标准还不够熟悉,不知道 why/if 它被接受了(例如,支持它的 g++ 4.9 可能是非标准的)。
被接受的论文版本是N3649
,我们可以去Evolution Working Group(EWG) Completed Issue 16: N3649, N3560, N3559, N3418 Proposal for Generic (Polymorphic) Lambda Expressions看看:
Reviewed by EWG in Portland 2012, proceeding with a follow-up paper.
Accepted into the Working Draft in Bristol 2013, as N3649.
Bristol 2013: Do not re-open proposals 2.1 and 2.2 in N3560, they are
considered NAD. The proposals 2.3 and 2.4 are covered by N3649.
请注意,此参考提案 2.1
和 2.2
是 NAD(不是缺陷)并且它们不会被重新打开。 N3560
从 N3418
中分离出来,N3418
是主要提案,N3560
中的提案 2.1
是:
Allow the use of familiar template syntax in lambda expressions
该论文注释提案 2.1
被认为有争议:
We admit that supporting the full template parameter list feature
has been deemed controversial (the Portland 2012 straw-poll outcomes
were: 7 SF, 5 F, 3 N, 1 A, 1 SA 1 ) by a few committee members, and
therefore conclude this sub-section with some quotes from a committee
member who was not present in the room during EWG's discussion of
this feature in Portland.
我们可以看到 N3649 不包含这个提案我从论文 N3560
中的引述猜测:
"
I think we need more than just
auto. I'm not sure how much more, but I think having just auto would be too limiting
".
是 auto 最终被认为是足够的,这与提案是 NAD
的说法是一致的,这意味着它试图解决的问题并不是一个真正的问题问题。
C++14 引入了通用 lambda。在浏览相关提案时,我发现 Faisal Vali、Herb Sutter 和 Dave Abrahams 提出的 N3418。 其中第 2.2 节的标题为:
2.2 Allow the use of familiar template syntax in lambda expressions
下面的代码示例包括这样的代码片段
[]<int N>(int (&a)[N]) {}
由于这些东西无法编译(使用 gcc、clang 和 Visual Studio),出现了一些问题:
- 这是一个实施问题吗?
- 是什么阻止了这部分被接受?
- 最终将通用 lambda 引入语言的提案是什么?
注意:我会对此发表评论,但没有这样的声誉。
如果我编译以下内容,你引用的精确结构就可以正常工作:
auto foo = []<int N>(int (&a)[N]) {};
与:
g++-4.9 -c foo.cpp -std=c++1y
但是,使用 g++-4.8
或 clang-3.6
都失败了。因此,我认为这是一个实施问题。但是,我对 C++14 标准还不够熟悉,不知道 why/if 它被接受了(例如,支持它的 g++ 4.9 可能是非标准的)。
被接受的论文版本是N3649
,我们可以去Evolution Working Group(EWG) Completed Issue 16: N3649, N3560, N3559, N3418 Proposal for Generic (Polymorphic) Lambda Expressions看看:
Reviewed by EWG in Portland 2012, proceeding with a follow-up paper.
Accepted into the Working Draft in Bristol 2013, as N3649.
Bristol 2013: Do not re-open proposals 2.1 and 2.2 in N3560, they are considered NAD. The proposals 2.3 and 2.4 are covered by N3649.
请注意,此参考提案 2.1
和 2.2
是 NAD(不是缺陷)并且它们不会被重新打开。 N3560
从 N3418
中分离出来,N3418
是主要提案,N3560
中的提案 2.1
是:
Allow the use of familiar template syntax in lambda expressions
该论文注释提案 2.1
被认为有争议:
We admit that supporting the full template parameter list feature has been deemed controversial (the Portland 2012 straw-poll outcomes were: 7 SF, 5 F, 3 N, 1 A, 1 SA 1 ) by a few committee members, and therefore conclude this sub-section with some quotes from a committee member who was not present in the room during EWG's discussion of this feature in Portland.
我们可以看到 N3649 不包含这个提案我从论文 N3560
中的引述猜测:
" I think we need more than just auto. I'm not sure how much more, but I think having just auto would be too limiting ".
是 auto 最终被认为是足够的,这与提案是 NAD
的说法是一致的,这意味着它试图解决的问题并不是一个真正的问题问题。