I would like to use a lambda as a parameter for a C++ function, but I don\'t know which type to specify in the function declaration. What I would like to do is this:
If this is an inline function, prefer a template, as in
template
void myFunction(Func const&lambda)
{
//some things
}
because it binds to anything that makes sense (and will cause compiler error for anything else), including lambdas, instances of named classes, and std::function<> objects.
On the other hand, if this function is not inline, i.e. implemented in some compilation unit, you cannot use a generic template but must use a specified type, which is best taken a std::function<> object and passed via reference.