|
|
|
|
|
by _lm_
3437 days ago
|
|
It's more readable, but using std::function here introduces a second layer of indirection vs using a plain function pointer. More specifically, std::function's operator() is virtual, and calls into a subclass that's specialized to function pointers of type void(int). The subclass then performs the actual function pointer call. |
|
This can be virtual functions, or, more commonly, an hand rolled vtable. In the last case, if std::function is constructed with a function pointer exactly matching its signature it could in principle avoid the thunk and directly point to the function itself. I don't think most implementations bother.
/pedantic