|
Boost Users : |
Subject: Re: [Boost-users] variant over base and derived classes
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-12-09 10:22:39
>>-----Original Message-----
>>From: "Diederick C. Niehorster" [dcnieho_at_[hidden]]
>>Date: 09/12/2010 01:51 PM
>>To: boost-users_at_[hidden]
>>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,
This works. The source is pasted below.
I am however obliged to
1. declare a default-constructed variant
2. call mpl::for_each on the sequence of types in the variant a assign functor to assign to the variant.
Is there a way I can embed/simplify this 2 stage construction?
regards,
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