| ▲ | jcranmer 5 hours ago | |||||||||||||||||||||||||||||||
When you want to use lambdas, but your language doesn't have lambdas, so you reach for the nearest thing instead. | ||||||||||||||||||||||||||||||||
| ▲ | uecker 4 hours ago | parent | next [-] | |||||||||||||||||||||||||||||||
Lambdas are just anonymous nested functions. But I like named nested functions more because they are more readable and would prefer them in most cases. Ideally you have both as most languages have. I always wondered why C++ only added lambdas, but observing WG21 for a while, I assume this is just a random walk in language design. (not that it is different in WG14) | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | mananaysiempre 5 hours ago | parent | prev [-] | |||||||||||||||||||||||||||||||
C++ bundles together a way to write functions inline in an expression (what I’d call “lambdas” in general) and a way to create closures with strictly nested lifetimes, but there’s no law of nature tying the two together. Even in C++ the essentially separate declaration “auto f = [&](... blah ...) { ... 50 lines of code ... };” is pretty common. (And of course GCC’s nested functions predate C++11 by twenty years.) | ||||||||||||||||||||||||||||||||