Hacker News new | comments | show | ask | jobs | submit login

Lambdas are an incredibly useful construct, and, once you master them, they do make a lot of programming tasks much easier.

However, C++ lambdas picked the most horrifically ugly syntax possible, and they switch between three subtly different semantics (copy, reference, move) depending on a single glyph. I feel bad for the people working on modern C++ - maintaining backwards compatibility is a huge constraint upon design space.

I'm not surprised that lambdas slow down people that aren't already experienced with them. Since I rarely program in C++, whenever I go back to it, I always have to spend a bit of time bashing my head against the horrific syntax.

C++14 improves upon lambda captures a lot. I'm also not aware of a move capture, only "by reference" (&) and "copy" (=). In C++14 you're allowed to put arbitrary assignments into the capture, e.g.

    [foo=std::move(bar)]() {}

I did that in the C++11 days by creating a bastard class template that would subvert the copy operator and turn it into a move and capture that by value.

It was ugly as heck and was removed as soon as I have c++14

Serious question: how would you improve the syntax while maintaining their feature set (which is not huge, but includes a few important things)?

I understand that C++ lambda syntax can be confusing on first encounter, but after reading about them for five minutes it should be very naturally comprehensible to any experienced C++ programmer. It's terse, but very clear.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact