This week, Faisal Vali shared an initial "alpha" implementation of generic lambdas in Clang. Faisal is the lead author of the proposal (N3418), with Herb Sutter and Dave Abrahams.
To read and participate in the active discussion, see the message thread on std-proposals.
Here is a copy of Faisal's announcement:
Motivated by the positive feedback we received regarding Generic Lambdas (during the October 2012 ISO C++ Standards Meeting in Portland), I have implemented a reasonably complete (unless I am missing something obvious) implementation (http://faisalv.github.com/clang-glambda/) of most of the proposal (named lambda syntax for functions has not been attempted) using a fork of Clang.
We would like to encourage developers who are interested in this feature, to either compile the code or download the binaries (sorry, only Windows for now) and play with the implementation and provide us with feedback so that we can incorporate it within our next revision of the document.
The following link: http://faisalv.github.com/clang-glambda/, has some instructions (towards the bottom) on how to compile the code or use the binaries for Windows.
Any and all constructive feedback will be greatly appreciated.
The current version (12/2012) implements subproposals 2.1, 2.2, 2.3 and 2.5.
2.1 Allow the type-specifier within a parameter declaration of a lambda to be
auto
(i.e.auto
is mandatory)auto Sum = [](auto a, decltype(a) b) { return a + b; }; int i = Sum(3, 4); double d = Sum(3.14, 2.77);
2.2 Allow the use of familiar template syntax in lambda expressions
auto NumElements = []<int N>(auto (&a)[N]) { return N; }; int arri[]{1, 2, 3}; double arrd[]{3.14, 2.77, 6.626}; auto total = NumElements(arri) + NumElements(arrd);
2.3 Permit a lambda body to be an expression
int local = 10; auto L = [&](auto a) a + ++local;
2.5 Autogenerate a conversion to function pointer in captureless generic lambdas
auto L = [](auto a, decltype(a) b) { return a + b; }; int (*fp)(int, int) = L;
Thank you and looking forward to the feedback!
Add a Comment
Comments are closed.