|
Boost : |
From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2007-09-07 02:32:26
Hi Marco,
On 9/6/07, Marco Costalba <mcostalba_at_[hidden]> wrote:
> >
> > 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<> ?
>
The intended use of fusion::vector<> is to become a compile-time
container (think of mpl::vector<>) of the function
prototypes/signatures which the 'functor' wrapper should
implement/support. At the same time, a fusion::vector<> can map a
numeric index to a runtime instance (ala tuple) of the type defined in
the indexed element of the vector. In code, that looks like:
fusion::vector<int, double, string> a(1, 2.1, "1");
int i = get<0>(a); // 1 at compile time
double d = get<1>(a); // 2.1 at compile time
string s = get<2>(a); // "1" at compile time
Though I'm pretty sure I'm not doing Boost.Fusion docs justice by my
above description, I think it would be better if you checked it out
for yourself. ;)
>
> > 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.
>
I definitely hope you find Boost.Fusion useful as well -- it's already
been useful in my work, and I'm thankful there's something like this
that has come along.
-- 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