by TeMPOraL · 6y ago · 0 comments
const auto iAmANestedFun = [stuff](stuff) -> stuff { ... }
Particularly, if we could assume that nested functions automatically and properly capture the arguments to the parent function. const auto nestedfunc = [=](a,b) { /* */ };
Which isn't that much different to me than { /* some scope */
function nestedfunc(a,b) { /* */ }
}
const and auto are needed but because it's C++. Beyond that, you have an equals sign which is needed here but [=] which is three characters. Again, small differences, not sure why it looks that much worse. auto triple = [](auto x){ return 3 * x; }; auto f = [&](...) { ... };
That covers the majority of cases.well, how would you do that ?
PHP closures have to specify which variables they close over, and whether it's done by-val or by-ref [0].
Nowadays there's also a shorthand single-expression-closure syntax that closes implicitly and by value [1].
[0]: https://www.php.net/manual/en/functions.anonymous.php#exampl...
IIRC Rust uses capture modifiers similar to C++.