Re:Lambda expression comparison between C++11, C++14 and C++17
by kibwen on Saturday May 14, 2016 @06:15PM
(#11698298)
Very often the capture list is empty, it could have been elided (as the parameter list can be) if the syntax could have been made unambiguous.
[ Parent
| on HN ]
Re:Lambda expression comparison between C++11, C++14 and C++17
by yongjik on Saturday May 14, 2016 @06:19PM
(#11698314)
Well, you need something to indicate the beginning of a lambda. So you can think of "[]" as serving that role, instead of "lambda" in Python or "\" in Haskell.
Re:Lambda expression comparison between C++11, C++14 and C++17
by rubber_duck on Saturday May 14, 2016 @06:52PM
(#11698423)
You can use C# fat arrow syntax, it even allows removing the braces for single expression lambdas which is the most common from anyway.
Re:Lambda expression comparison between C++11, C++14 and C++17
by vanderZwan on Saturday May 14, 2016 @08:17PM
(#11698682)
> removing the braces
If I have learned anything over the years, it's that removing the braces anywhere is the introduction of a bug during a rewrite waiting to happen.
Re:Lambda expression comparison between C++11, C++14 and C++17
by rubber_duck on Sunday May 15, 2016 @04:32PM
(#11702602)
It really works without any issues in C# from my experience.
Statemends like :
list.Where(e => e.Property == ExpectedValue).Select(e => e.Property)
is much cleaner than something like : list.Where([](auto e) { return e.Property == ExpectedValue; }).Select([](auto e) { return e.Property; });
Braces and capture declaration adds 0 value here and it's ~80% of the use cases I see for lambdas.