auto compose = []( auto f, auto g )
[=]( auto x ) f( g(x) );
auto curry3 =
[]( auto f )
[=](auto x) [=](auto y) [=](auto z)
f(x,y,z);
And variadic lambdas, too! Very nice.
But I wonder why we couldn't...
auto f = []( auto _f ) [](auto ...x) _f(x...);
I wrote some tests. A few lines caused the compiler to crash so I commented them out and labelled them "Crash!".
https://gist.github.com/4347130
Composition and currying are cool.
Those who don’t like the terse syntax may object that it’s only slightly worse with the current syntax, though, right?
auto compose = []( auto f, auto g ) { return
[=]( auto x ) f( g(x) ); };
auto curry3 =
[]( auto f ) { return
[=](auto x) { return [=](auto y) { return [=](auto z) { return
f(x,y,z); }; }; }; };
Though you do have to be a little careful to balance the {‘s and };’s.
Herb
--
--
[] (a) {}
Is `a` an automatically-typed variable or an unnamed argument with the type `a`?
so, maybe it'd make sense to introduce some special keyword to disambiguate these cases?
On Tuesday, December 18, 2012 5:50:50 PM UTC+2, tra...@solidfire.com wrote:The `auto` is required is disambiguate this:
[] (a) {}
Is `a` an automatically-typed variable or an unnamed argument with the type `a`?
class A{}; class B{}; class C{};
typedef void (*callback1)(A /*required*/, B /*optional*/);
typedef void (*callback2)(A /*required*/, C /*optional*/
);
void func(callback1);
void func(callback2);
void foo() {
func([](A a, B){ /*Do stuff with only a
*/});
}
- Daniel
--
- Daniel
--