Boost logo

Boost :

From: Jesse Jones (jejones_at_[hidden])
Date: 2000-11-16 20:55:36

>So... before we discuss the thread specific stuff I'd like to first
>address callbacks. I've read all the articles on the subject that I
>can get my hands on and it seems they all take different approaches
>(the Kubrick article covers several of them), each with varying pros
>and cons. I'd like to describe what requirements I think our version
>of callbacks need to take just to make sure everyone agrees with my
>opinions before we attempt to create an actual implementation.
>1. Need to allow traditional functor types as the callback so that
>function pointers, standard functors, hand coded functors and Lambda
>Library style functors can all be used with relative ease.

I'd go with allowing callbacks to be constructed with either a functor or
an object/member function pointer. The second is probably redundant, but
it's such a common operation that it should be very easy to do.

>2. The callback type(s) should be templatized on the return type and
>argument types, but not on the functor type to simplify useage.

This is important. I use callbacks quite a bit with non-template code and
it would be a major hassle if I had to templatize them just to use a

>3. Copying a callback should be quick, on par with copying a
>function pointer. This is not gauranteed with functors but becomes
>somewhat important with callbacks that may be stored, copied and
>passed around frequently in some cases.

We probably also want to be able to test for equality. Possibly ordering as

>4. A callback should itself be a functor.

Along the same lines it's very useful to be able to bind one or more
arguments. This is pretty easy to do even without a full blown lambda

>5. Compiler type coercion should be possible to apply to the functor
>that the callback wraps for all parameters and the return value.

This is also very useful. It lets you do things like assign to a callback
that takes an int argument a function that takes either an int or a long.
Or, alternatively, you can assign a function with two arguments to a
callback with one if the second argument has a default value.

Along the same lines it's useful to assign a function that returns a value
to a callback that returns void.

>Do you agree or disagree with any of the above? What other
>requirements should there be? Any other ideas or comments? Is there
>someone interested in submitting an implementation for Boost?

I can submit some code that fulfills all of the goals you mentioned as well
as the ones I listed above.

  -- Jesse

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