Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2007-09-07 02:08:11


On 9/6/07, Dean Michael Berris <mikhailberis_at_[hidden]> wrote:
>
> is passed to it -- only Boost.Signals is an excellent implementation
> of the publish-subscribe channel pattern, whereas the dispatcher is
> meant to be an implementation of a message router pattern.
>

Thanks for your hint, I will study Boost.Signals then.

>
> void foo(int a) { ... };
> void bar(int a, int b) { ... };
> void foobar(int a, double b) { ... };
>
> dispatcher< fusion::vector<void(int), void(int,int), void(int, double)> > d;
> d[0] = &foo;
> d[0] = &bar;
> d[0] = &foobar;
>
> If you look at the implementation(s) for the "functor" type in the
> dispatcher, it would be possible for it to provide the three
> operator() overloads following signatures given as a fusion::vector<>
> by containing three boost::function<>'s each having one signature, and
> having the deduction done during compile-time still. So that means:
>
> d[0](1); // foo() is called
> d[0](1, 2); // bar() is called
> d[0](1, 2.1); // foobar() is called
>

More or less I can achieve this also with my very simple and raw
implementation, what I cannot achieve is something like this:

void foobar3(int a, double b, double c) { ... };
void foobar4(int a, double b, std::string) { ... };

d[0] = &foobar3;
d[0] = &foobar4;

d[0](1, 1, 1); // foobar3() is called

d[0](1, 2.4, "Test"); // foobar4() is called

Is this possible using fusion::vector<> ?

> I think Boost.Fusion
> will definitely help in this extension through the fold<>
> algorithm/metafunction (for linear inheritance for the signature
> overloads).
>

Boost.Fusion is another place where I'm going to look :-) thanks.

Marco


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