Daily bit(e) of C++ | Lambda to function pointer
Daily bit(e) of C++ #270, Forcing conversion of lambdas to function pointers.
Lambdas with empty capture are still function objects but can be implicitly converted to function pointers.
In some contexts (notably when type deduction is involved), it can be helpful to force this conversion.
One approach is static_cast, but the unary plus operator offers a more concise approach.
What is the use case of this?
Is it more performant to use function pointers? I was under the impression that lambdas are performant in C++, given that it’s just syntactic sugar for function objects (functors). I know std::function isn’t as performant since the compiler cannot inline, due to inability to deduce the function.