Boost logo

Boost :

Subject: Re: [boost] Downcast taking account of virtual inheritance
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-02-14 14:55:21


----- Original Message -----
From: "Robert Ramey" <ramey_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, February 14, 2010 6:47 PM
Subject: Re: [boost] Downcast taking account of virtual inheritance

>
> As part of your efforts, you might want to checkout "smart_cast"
> which is a documented part of the serialization library.

The idea correspond quite closely to my needs. I have used it in my code and it works.

The implementation is based on whether the base type is polymorphic, not whether the base type is_virtual_base_of<B,D>.
I have replaced

            template<class U>
            static T cast(U * u){
                    typedef
                        BOOST_DEDUCED_TYPENAME mpl::eval_if<
                            BOOST_DEDUCED_TYPENAME mpl::and_<
                                mpl::not_<is_base_and_derived<
                                    BOOST_DEDUCED_TYPENAME remove_pointer<T>::type,
                                    U
> >,
                                mpl::not_<is_base_and_derived<
                                    U,
                                    BOOST_DEDUCED_TYPENAME remove_pointer<T>::type
> >
>,
                            mpl::identity<cross>,
                            mpl::identity<linear>
>::type typex;
                    return typex::cast(u);
            }
by
            template<class U>
            static T cast(U * u){
                    typedef
                        BOOST_DEDUCED_TYPENAME mpl::eval_if<
                            is_virtual_base_of<U, BOOST_DEDUCED_TYPENAME remove_pointer<T>::type>,
                            mpl::identity<cross>,
                            mpl::identity<linear>
>::type typex;
                    return typex::cast(u);
            }

And it work also. But now dynamic_cast is used only if U is virtual_base_of T.
Can this be added to smart_cast?

Thanks,
Vicente
 


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