If you commit g by reference, that is, with the &g syntax specified in your snippet, the copy will fail. This is the preferred method. You should only copy if lambda can be called after completion of f , which potentially implies the destruction of g . In this case, shipping may be cheaper:
template<class Function> void f(Function&& g) { h(β¦, [g=std::forward<Function>(g)] {g();}); }
source share