2025. 5. 23. 18:47

A lambda to a pointer to function

Recently, I changed the lambda code to capture a local variable, and then the code didn't compile.
What I found was that only a lambda without capture can be converted to a function pointer.

 

[expr.prim.lambda]

The closure type for a lambda-expression with no lambda-capture has a public non-virtual non-explicit const conversion function to pointer to function having the same parameter and return types as the closure type's function call operator. The value returned by this conversion function shall be the address of a function that, when invoked, has the same effect as invoking the closure type's function call operator.