auto-declared variable holding a closure has the same type as the closure, and as such it uses only as much memory as the closure requires. The type of a
std::function-declared variable holding a closure is an instantiation of the
std::function template, and that has a fixed size for any given signature. This size may not be adequate for the closure it’s asked to store, and when that’s the case, the
std::function constructor will allocate heap memory to store the closure. The result is that the
std::function object typically uses more memory than the
auto-declared object. And, thanks to implementation details that restrict inlining and yield i...
Comparison between "auto" and "std::function".
Share this highlighthttp://www.safaribooksonline.com/a/effective-modern-c/365333/