Quick Q: When should I use std::function vs. make my function a template? -- StackOverflow
To accept a functor as a parameter, when should you:
-
accept a
std::function, which adds an indirection, vs. -
make your function a
template<class Func>and accept aFunc, which can bind directly to whatever is passed?
std::function vs template
Thanks to C++11 we received the
std::functionfamily of functor wrappers. Unfortunately, I keep hearing [...] that they are horribly slow. [... Is the right recommendation] thatfunctions can be used as de facto standard of passing functors, and in places where high performance is expected templates should be used?

Herb Sutter's biggest and deepest talk at
Two advanced talks by Stephan T. Lavavej (aka STL) are now available, the second being posted today: