
----- Original Message ----- From: "Robert Ramey" <ramey@rrsd.com> To: <boost@lists.boost.org> 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