Live data from Hacker News

C++14 lambda tutorial

solarianprogrammer.com

31–32 of 32 posts

Re: C++14 lambda tutorial

#31
post #4

Earlier quoted context omitted.

Not shown in this article are all the things you can do within the [] (typically just [&] or [=]), which turns a simple lambda into a closure. The syntax is a bit arcane, but it does what it needs to. They could've stuck a "lambda" keyword in front of it all, but it's not necessary, and making a new keyword always has the potential to break old code.

is it possible to do #define lambda [] ?

That way lies http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/...

Re: C++14 lambda tutorial

#32

Earlier quoted context omitted.

Do you have an alternative suggestion? It seems reasonably straightforward to me and I don’t find it all that impossible. Not having to muck around with a specific lambda() factory-like function with horrible inputs (as is needed in LPC where I sort-of learnt to code) is a plus :)

I don't mind C++'s lambdas, but in some other languages they use "arrows", like square = (x) -> x * x C++ won't want to give up the different kinds of capturing, though, so it's hard to see anything much better than what's available now. In imaginary, never-to-be-implemented language daydreams I toy with the idea of using curly braces and implicit positional arguments to have lambdas look like square = { _1 * _1 } an…

""In imaginary, never-to-be-implemented language daydreams I toy..""

Your mockup code sure looks like Lua.

Post reply on HN