what would nested functions bring you that lambdas don't ?
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; };well, how would you do that ?
IIRC Rust uses capture modifiers similar to C++.
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...
auto f = [&](...) { ... };
That covers the majority of cases.https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html#Nes...
std::sort(vec.begin(), vec.end(),
[] (const auto& lhs, const auto& rhs) {
return lhs.whatever < rhs.whatever;
});
or auto sort_by_whatever = [] (const auto& lhs, const auto& rhs) {
return lhs.whatever < rhs.whatever;
};
std::sort(vec.begin(), vec.end(), sort_by_whatever);