Boost logo

Boost Users :

Subject: Re: [Boost-users] variant over base and derived classes
From: Dave Abrahams (dave_at_[hidden])
Date: 2010-12-09 11:56:31


At Thu, 09 Dec 2010 09:15:45 -0500,
Hicham Mouline wrote:
>
>
> >Subject: Re: [Boost-users] variant over base and derived classes
>
> >(sorry if this is a top post, my phone shows no msg quotes)
>
> >I'm no expert on this, but isn't there an compile time function to
> >testing if an instance is derived from another (in introspection or
> >something)? You could then maybe sort the variant types for most to
> >least derived and then test untill you find the suitable cast?
>
> >Just brainstorming pretty much. Hope its useful!
> >Best,
> >Dee
>
> yes, there is boost::is_base_of or some metafct like that in type_traits.
> not quite sure how to implement the sort though?
> will checkout mpl::sort with binary predicate base_or_derived.
> I have under 10 types, so compile time should be ok
> thanks,

I haven't looked at your use-case in detail, but it's a bit of a
stretch to imagine a case in which runtime polymorphism via virtual
functions would be useful inside a variant, since you need to know the
most derived type of each stored thing anyhow. Are you going to be
referring to the stored items via a base class pointer?

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net