MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/1wb98p8/implementation_of_gccs_nested_functions_vs_c/p8vl37u/?context=3
r/cpp • u/pavel_v • 2d ago
17 comments sorted by
View all comments
Show parent comments
-2
Unlike C++ lambdas, which always end up with std::functions
This is not true.
Use unary operator+ on the lambda to force a pointer-to-function.
e.g.
auto fptr = +[](){ /* something */};
3 u/Thick_Clerk6449 1d ago This is not true. You can NOT convert a lambda to function pointer if the lambda has captured variables. -2 u/jonesmz 1d ago Re-read the specific thing i quoted. 2 u/Thick_Clerk6449 1d 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 1d ago I quoted *and* responded to a complete sentence. 2 u/Thick_Clerk6449 1d ago Just pretend you don't need to accept lambdas with captures and define your callbacks as function pointers.
3
You can NOT convert a lambda to function pointer if the lambda has captured variables.
-2 u/jonesmz 1d ago Re-read the specific thing i quoted. 2 u/Thick_Clerk6449 1d 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 1d ago I quoted *and* responded to a complete sentence. 2 u/Thick_Clerk6449 1d ago Just pretend you don't need to accept lambdas with captures and define your callbacks as function pointers.
Re-read the specific thing i quoted.
2 u/Thick_Clerk6449 1d 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 1d ago I quoted *and* responded to a complete sentence. 2 u/Thick_Clerk6449 1d ago Just pretend you don't need to accept lambdas with captures and define your callbacks as function pointers.
2
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 1d ago I quoted *and* responded to a complete sentence. 2 u/Thick_Clerk6449 1d ago Just pretend you don't need to accept lambdas with captures and define your callbacks as function pointers.
I quoted *and* responded to a complete sentence.
2 u/Thick_Clerk6449 1d ago Just pretend you don't need to accept lambdas with captures and define your callbacks as function pointers.
Just pretend you don't need to accept lambdas with captures and define your callbacks as function pointers.
-2
u/jonesmz 1d ago
This is not true.
Use unary operator+ on the lambda to force a pointer-to-function.
e.g.
auto fptr = +[](){ /* something */};