I am trying to use a lambda with state as a function pointer parameter, state here meaning that it captures from it's context. According to this issue that's not legal: Why does the implicit "lambda to function pointer conversion" forbid the "by reference" capture of static members?
Current function I want to pass the lambda to: void foo( void( func* )( unsigned long ) )
This is a simplified version of where I'm creating the lambda I want to pass:
void MyClass::myClassFunc( int a, int b, int c )
{
auto myLambda = [&]( unsigned long val ){ a+=val;b+=val;c+=val; };
foo( /*some magic conversion*/ myLambda );
}
Easy solution, overload foo
: void foo( std::function< void( unsigned long ) > func )
The easy solution is undesirable because it requires me to modify code that isn't mine. Is there a way that I can somehow convert the lambda only in calling code?