|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2000-11-18 21:26:58
I've posted an implementation prototype at http://www.egroups.com/files/boost/Callback/ which I believe meets all of the prior requirements, including compilation on MSVC++ 6.0 (sp4).
Usage:
- The "callback" class is the only class visible to the user. Callbacks are defined as such:
callback<return_type, arg1_type, arg2_type, ...> my_callback;
where some number of arguments (0 up to some predefined limit) may be specified.
- Any functor taking appropriate argument types (arg1_type, arg2_type, etc must be convertible to the argument
types taken by the functor) and returning an appropriate type (convertible to return_type) may be used as the
callback target. Functors are assigned directly to the callback, e.g.,
my_callback = my_functor();
- Callbacks are functors, so the function call operator is overloaded with the given argument/return types.
- Callbacks are convertible to bool. True indicates that there is a callback target, false otherwise. The empty()
member returns true if there is no callback target, false otherwise.
The cost of a callback is equal to the cost of a virtual call plus a call to the functor itself. The size of a
callback is that of the virtual function table for one function plus the size of the target functor. Copying a callback is
reasonably quick (the cost of copying a shared_ptr).
Platforms tested (success):
- Microsoft Visual C++ version 6 (service pack 4) on Windows 98
- g++-2.95.2 (-ansi -pedantic -W -Wall) on x86 Linux
Platforms tested (failure):
- SGI MIPSpro 7.3 (error in smart_ptr.h - did not look further)
- egcs-2.7.2.3 (namespaces broken, compiler crashes)
Doug Gregor
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk