Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2007-09-30 11:12:19


On 9/30/07, Dean Michael Berris <mikhailberis_at_[hidden]> wrote:
> >
> > is not clear to me when and where this invokers are called given that
> > dispatcher::operator[] returns a function object reference. Or perhaps
> > I misread.
> >
>
> Can you refer to which page in the documentation you see that?
>

If you mean the above example is in:
dispatcher-0.2/libs/dispatcher/doc/index.html

> The invoker is intended to be used this way:
>

Thanks, now it's much more clear.

>
> The immediate "top of my head" implementation would be to do a linear
> inheritance of the different Functor objects that support different
> signatures to represent a multi-signature Functor wrappers.

--------- cut ---------------

>
> void foo(double d) ;
> void bar(string s) ;
> void fizz(int i) ;
>
> multi_index_dispatcher d;
> d[0] = foo; // valid, will register the void(double)
> d[0] = bar; // valid, will register the void(string)
> d[0] = fizz; // valid, will register the void(int)

Also Dispatcher::operator=() should be 'stacked' in some way though...but how?

> d[0](1.0); // valid, will call the void(double)
> d[0](1); // valid, will call the void(int)
> d[0]("1"); // valid, will call the void(string)
>
> This might also be achievable with an encapsulated Fusion map instead
> of linear inheritance, but I'm not entirely sure about being able to
> generate the appropriate type-safe operator() overloads in that
> manner.
>

Perhaps if the key of the map is the function signature could be
possible first find a match with the supplied arguments and then call
the operator(), should be safe in that case. A (big) downside is that
you forget implicit conversions this way.

>
> Thank you for the interest, and I definitely hope the above
> explanation helps. :)
>

Helped a lot.

Thanks
Marco


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