As far as I know, I have at least the following three ways to declare a function which accept closures:
- by copying
- by reference
- by moving
e.g.
void FooCopyLambda(std::function<void()> f) {
// ...
f();
// ...
}
void FooRefLambda(const std::function<void()> &f) {
// ...
f();
// ...
}
void FooMoveLambda(std::function<void()> &&f) {
// ...
f();
// ...
}
In This question, people discussed how to pass by reference. But here I also want to know, should I pass it by reference? Or maybe I should pass it by value or moving?
What's the proper way to pass lambda as an argument? Why?