Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2007-09-02 07:56:49


Hi Tobias!

On 9/2/07, Tobias Schwinger <tschwinger_at_[hidden]> wrote:
>
> Same with the code I posted.
>
> The factories are just adapters to make a construction expressions
> first-class function objects which are then type-erased and stored in
> 'boost::function's...
>
> So it seems a
>
> 'dispatcher<Key,Sig>'
>
> is pretty much like a
>
> 'std::map<Key,boost::function<Sig> >'
>
> ;-).
>

Yes, and I would suggest that if the added features of the dispatcher
aren't required (like the index validation,
routing/message-transformation, exception-friendly functor wrapper,
and the invoker interface) then a map would do just fine.

Though it is interesting -- I've been playing around with the idea of
an overloaded type-safe dispatcher for some time, but I never got to
thinking of a way to accomplish it in a clean manner. Basically
something that will allow the following:

void foo1(int a) { ... };
void foo2(int a, int b) { ... };

dispatcher<signatures<void(int), void(int, int)>, string> d;
d["foo"] = &foo1;
d["foo"] = &foo2;

d["foo"](1); // will call foo1(...)
d["foo"](1, 2); // will call foo2(...)
d["foo"](1, 2, 3); // will not compile

Perhaps it might be doable, even with the current code I already have
there but Real Life (TM) and not enough interest (or utility) from the
community really bars me from doing much about it. Maybe when Real
Life (TM) lets up, I might come around to allowing this.

:-)

-- 
Dean Michael C. Berris
http://cplusplus-soup.blogspot.com/
mikhailberis AT gmail DOT com
+63 928 7291459

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