Proper way to receive a lambda as parameter by reference
You cannot have an auto parameter. You basically have two options: Option #1: Use std::function as you have shown. Option #2: Use a template parameter: template<typename F> void f(F && lambda) { /* … */} Option #2 may, in some cases, be more efficient, as it can avoid a potential heap allocation for the embedded … Read more