Use a lambda as a parameter for a C++ function [duplicate]

You have 2 ways: make your function template:

template <typename F>
void myFunction(F&& lambda)
{
    //some things
}

or erase type (with std::function for example):

void
myFunction(const std::function<void()/*type of your lamdba::operator()*/>& f)
{
    //some things
}

Leave a Comment