Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-06-08 05:39:37


Dean Michael Berris wrote:

> //set up a registry
> dispatch::dispatcher<void (), int> callbacks;
>
> // register a nullary free function f to index 0
> callbacks[0] = f;
>
> // bind arguments to a single argument function p to index 1
> callbacks[1] = boost::bind(p, 1);
>
> // get user input then execute appropriate callback
> int i;
> cin >> i;
> callbacks[i]();

This can be done with map< int, function<void()> >.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk