|
Boost : |
From: Doug Gregor (dgregor_at_[hidden])
Date: 2006-05-02 15:15:12
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk