The following program do not compile :
#include
#include
#include
#include
#include
You are effectively referencing f, which is a variable in the outer scope, in your lambda. You should capture it in your capture list (simplest is probably by reference [&f], or [&] to capture everything by reference, as you are using it immediately).
On another note, std::function has some overhead as it performs type erasure, in your case here it might be better to introduce a template type.