3 ms·
eh.... having to deal with Python's stupid lambdas, C++ lambdas are far superior. You can always do: auto func = [](...){....} for nested funcs
by cheez 6y ago
eh.... having to deal with Python's stupid lambdas, C++ lambdas are far superior. You can always do:
auto func = [](...){....}
for nested funcs
- deleted 6y ago[deleted]
- f00zz 6y agoYeah, using lambdas as nested functions is pretty common.
- rightbyte 6y agoYe but I would just want the possibility for the simpler syntax like the GCC extension for C where you can do: typedef void fp_t(); void foo(fp_t fp) { fp(); } int square(int num) { void square_nested() { num = num * num; } foo(square_nested); return num; } That would work as long as you don't need copy capture.
- cheez 6y agoI really don't see how that is so much better than the alternative that it would warrant a language change: int square(int num) { auto nested = [&num](){ num *= num; }; nested(num); return num; }
- rightbyte 6y agoI agree, given the fact that lambdas are already here.
- cmeacham98 6y agoSlight mistake: should be auto nested = [](int& num){ (or switch calling nested to have no params)
- cheez 6y agoThe HN C++ compiler ;-)