|
Boost Users : |
Subject: Re: [Boost-users] variant over base and derived classes
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-12-09 12:33:04
>Â ----Original Message-----
>From: "Dave Abrahams" [dave_at_[hidden]]
>Date: 09/12/2010 05:00 PM
>To: boost-users_at_[hidden]
>Subject: Re: [Boost-users] variant over base and derived classes
>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
I have a class hierarchy that I want to be able to mpi::broadcast.
mpi::broadcast not being able to polymorphically receive the object on the receiver's end forced me to wrap all the hierarchy in a variant, which I can send and it works at reception as well.
at reception, mpi::broadcast requires the real object to exist already.
The code that sends with mpi::broadcast receives a base class reference (or pointer).
The code that receives with mpi::broadcast doesn't know what it is receiving.
Apparently, boost::serialization can deal with base pointers fine, and I think it creates on the heap the loaded objects, or?
The solution w variant works here, I am trying to simplify.
thanks,
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