Boost logo

Boost Users :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-08-26 13:32:44

On Tuesday 26 August 2003 01:57 pm, shyamemani wrote:
> I was reading the Herb Sutter's article Generalizing Observer in
> CUJ where he uses this functionlity to implement a generic call
> back. But I have some issues:
> By using this library we can eliminate the function name
> dependency introduced by using a call back interface and can call
> any function which matches the signature. But wouldn't this cause a
> maintainance problem? Using the call back interface defines the
> name of the function, it is easy to find the execution block for an
> event. Using this library it becomes a more of a coding convention
> than a compile time check.

In my experience it has not caused a maintenance problem, and in fact it often
helps to decouple an operation from the code that reports the progress of the

> It may have removed the cost of virtual function call but I
> think the performance would be offset by the extra call to operator
> (). So though it is a very good feature of language, does it not
> open doors for more cost?

Sure, it could. Calling through a function<> object incurs some additional
overhead, but it has its benefits. The cost of extra call to operator()
(e.g., of a function object in stored in a function<>) is either negligible
(if operator() does something real) or operator() will be inlined anyway (if
operator() is small).

FWIW, I've heard lots of concerns from those that might use that
boost::function<> may be too slow, but never any complaints from users that
it is in fact too slow.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at