Re: [Boost-users] variant over base and derived classes

-----Original Message----- From: "Diederick C. Niehorster" [dcnieho@gmail.com] Date: 09/12/2010 01:51 PM To: boost-users@lists.boost.org 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,

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
participants (2)
-
Dave Abrahams
-
Hicham Mouline