3 ms·
Ye 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)
by rightbyte 6y ago
Ye 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 ;-)