Boost logo

Boost :

From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-05-10 11:51:18


On Sat, May 10, 2008 at 10:32 AM, Marco Costalba <mcostalba_at_[hidden]> wrote:
> On Sat, May 10, 2008 at 3:17 AM, Giovanni Piero Deretta
> <gpderetta_at_[hidden]> wrote:
> >
> > 1) can you dispatch on the dynamic type of an object? I.e.
> >
> > struct Base { virtual ~Base() {} };
> >
> > struct A : Base {};
> > struct B : Base {};
> >
> > void foo1(A&);
> > void foo2(B&);
> >
> > f = foo1;
> > f = foo2;
> >
> > A a;
> > B b;
> > foo((Base&)a); // calls foo1
> > foo((Base&)b); // calls foo2
> >
>
> Probably you mean
>
> f((Base&)a); // calls foo1
> f((Base&)b); // calls foo2
>
>
> Anyway no you can't. But because also boost::function can't I fail to
> see an inconsistency. Indeed
>
> boost::function<int(A&)> f= foo1;
>
> f((Base&)a); // calls foo1 <---- COMPILER ERROR: cannot convert
> parameter 1 from Base to A&
>

Ok. I know that boost function can't do it, but I thought that dynamic
dispatching
would come easier once you had multiple overload dispatching
functionality. Thinking
of it, it probably needs registering all derived types of Base.

Anyways I do not think that MSF should provide this, it was just a whish :)

>
>
> >
> > 2) If I have a polymorphic function object, can I store a single
> > instance of this object
> > and specify multiple signatures? i.e.
> >
> > struct foo_t { template<class T> void(T){...} } foo;
> >
>
> Sorry but the line
>
>
> struct foo_t { template<class T> void(T){} } foo;
>
> does not compile for me. Probably I'm missing something obvious.
>

I'll reply to this in another email.

-- 
gpd

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