Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2006-10-19 13:22:43


Hi Janek,

On 10/20/06, Janek Kozicki <janek_listy_at_[hidden]> wrote:
> Dean Michael Berris said: (by the date of Thu, 19 Oct 2006 17:09:02 +0800)
>
> > > > can it be used for multimethods ?
> > >
> > I have an example use (in the accompanying tests) which uses a
> > boost::tuple<> as the index type. If the aim was to use multiple
> > values, you can create a tuple from it and use that as an index --
> > then couple it with a validation and routing strategy that allows you
> > to validate and manipulate the index used for the dispatch.
> >
> > If you need to call multiple methods, you can use the invoker
> > interface to the dispatcher -- but still using single dispatch. You
> > can even use Boost.Signals to register a set of methods and register
> > it to the dispatcher on a single index.
>
> thanks, I will check it out. I have one question though. Currently I am
> using a 2D matrix to preform dispatching on two virtual base classes.
> This matrix approach allows fast lookup. Does your method allow a
> similar solution?
>

I haven't checked out how the dispatcher plays on the traditional
object oriented models: inheritance and multiple inheritance. However,
the idea of using a 2D matrix can be solved by perhaps using a tuple
as the index to the associated method/function. An example below might
give more light:

boost::dispatch::dispatcher<void(), boost::tuple<int, int> > d;
d[make_tuple(0, 0)] = function_1;
d[make_tuple(0, 1)] = function_2;
d[make_tuple(1, 0)] = function_3;
d[make_tuple(1, 1)] = function_4;
// ...
int x, y;
std::cin >> x >> y;
d[make_tuple(x, y)]();

HTH! :-)

-- 
Dean Michael C. Berris
C++ Software Architect
Orange and Bronze Software Labs, Ltd. Co.
web: http://software.orangeandbronze.com/
email: dean_at_[hidden]
mobile: +63 928 7291459
phone: +63 2 8943415
other: +1 408 4049532
blogs: http://mikhailberis.blogspot.com http://3w-agility.blogspot.com
http://cplusplus-soup.blogspot.com

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