
On May 2, 2006, at 2:46 PM, Tobias Schwinger wrote:
Curious question:
Say we use a functor class template adapter with a function pointer as non-type template parameter...
In case we pass it to function templates that treat functors uniformly (such as std algorithms), the compiler has (at least theoretically) a fair chance to make an absolute call or even to inline.
Boost.Function, however, implements distinct handling for function objects and function pointers. So, is there any chance for reducing the work at the call site with this technique?
Sure. When you stick a function pointer into a boost::function, you actually get two indirect calls for each invocation: the first goes from the boost::function::operator() to a "manager" that encodes the type of the function pointer, and the second goes through the function pointer to the function. If you encode the function pointer in the type of the function object that you stick into boost::function, the compiler can eliminate the second call. Doug