Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-11-17 13:07:36

From: <spam2002_at_[hidden]>
> This fact (and because I think using functors for publish-subscribe
> is a good idea) forced me to write my own functor library, which
> implements almost the same functionality as boost::function,
> boost::bind and boost::mem_fn together (with quite a different
> interface though and without providing automatic conversion
> from "foreign" functors of course).

What does "foreign" function object mean?

> 0. Am I missing something??

Not likely.

> 1. What was the design rationale behind prefering the possibility to
> adapt "foreign" function objects over the possibility to use
> boost::function in publish-subscribe schemes? IMHO, the latter is
> probably needed by more programmers.

boost::function can be used in publish/subscribe schemes. On subscription,
you need to identify the subscriber by a unique identifier.

template<class F> void subscribe(std::string const & id, F f);

This doesn't place any requirements on F and doesn't couple the subscriber
identity with the action that is performed on publish.

The identifier may be a string (as it is in my messaging subsystem), or it
might be a void const * (if you need to identify objects by address.)

If you insist on automatically deducing the subscriber identity from the
action, I don't see an easier way to do this besides reimplementing
function/bind or moving to object-based subscribers (ABC with a pure virtual

> 2. As mentioned above, there seems to be no way to extend
> boost::function, boost::bind and boost::mem_fn to provide equality
> operations AND automatic conversions from "foreign" functors.

There isn't because function/bind have no concept of a 'foreign' function
object. Any function object is as good as the next.

Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at, gregod at, cpdaniel at, john at