The following program do not compile :
#include
#include
#include
#include
#include
You use the f
parameter in the lambda inside asort()
, but you don't capture it. Try adding f
to the capture list (change []
to read [&f]
).
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.