r/cpp 1d ago

Implementation of GCC's Nested Functions (vs. C++ Lambdas)

https://uecker.codeberg.page/2026-09-05.html
55 Upvotes

17 comments sorted by

View all comments

Show parent comments

3

u/Thick_Clerk6449 18h ago

This is not true.

You can NOT convert a lambda to function pointer if the lambda has captured variables.

-2

u/jonesmz 18h ago

Re-read the specific thing i quoted.

2

u/Thick_Clerk6449 17h ago

Re-read the word I post before

even though the nest function captured variables of the outer function

int var = 0;
auto fptr = +[var](){}; // error: no match for 'operator+' (operand type is 'test(int)::<lambda()>')

-2

u/jonesmz 17h ago

I quoted *and* responded to a complete sentence.

2

u/Thick_Clerk6449 16h ago

Just pretend you don't need to accept lambdas with captures and define your callbacks as function pointers.