boost::function<void(void)> serves this purpose
for me in jass. To
create and pass a functor that assigns a new
auditor generator to the
one in the engine, and then tells it to play i do for example:
write_blocking_command(assign(engine_.auditor_gen, p));
write_blocking_command(boost::bind(&engine::play_auditor,
boost::ref(engine_))); assign() is just a utility template to make
creating functors that do assignments easier.. boost::bind is used to
make all passed functors 0-ary (e.g for binding member functions to
their instance or binding arguments to the functor.. and
write_blocking_command is just a utility function that disables the GUI
until the acknowledgement from the engine has come back to the GUI,, The
command ringbuffer is just a ringbuffer holding
boost::fucntion<void(void)> objects..
typedef ringbuffer<boost::function<void(void)> > command_ringbuffer;
Examples from here:
https://github.com/fps/jass/blob/master/main_window.h
https://github.com/fps/jass/blob/master/assign.h
https://github.com/fps/jass/blob/master/engine.h Regards, Flo
There are
alternatives (even predecessors) to boost.function that
are much faster and avoid the heap/new. See
<http://www.codeproject.com/KB/cpp/fastdelegate2.aspx> for example.
(I used Don's original "Fastest Possible C++ Delegates" on an embedded
project years ago -- worked great).