What is the best practice when passing lambda to a function? I can think of two ways for now. What would you choose and what are the tradeoffs? What other approaches are available? Any pointers to reference or blog posts are welcome. Thank you.
// Option 1. writing out the function spec
int apply(std::function<int(int,int)> fn, int x, int y
) {
return fn(x, y);
}
// Option 2. use a template and let it figure out by itself
template <typename T>
int apply(T fn, int x, int y) {
return fn(x, y);
}