RE: [boost] Does anyone have an is_virtual_base_and_derived ?

I wrote that very thing a year or so ago for the purpose of testing if a base pointer type can be statically downcast to a derived type. I don't claim to have tested all permutations of its usage, but it certainly worked on the cases I was testing it with. However, it does have the unfortunate side-effect of generating an 'ambiguous base' warning on the later GCCs every time it is used with a class which inherits another non-virtually. (though the traits class still gives the correct answer) If anyone can find a way of preventing this warning, or even an alternate implementation, I'd be glad to hear it. Here is my basic implementation: #include <boost/config.hpp> #include <boost/type_traits/is_convertible.hpp> namespace is_virtual_base_and_derived_detail { #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4250) #endif template <typename BaseImpl, typename DerivedImpl> struct tester : public DerivedImpl, virtual public BaseImpl { tester(); tester(const tester&); }; #ifdef _MSC_VER #pragma warning(pop) #endif template <typename Base, typename Derived, bool IsBaseAndDerived> struct impl; template <typename Base, typename Derived> struct impl<Base, Derived, true> { BOOST_STATIC_CONSTANT(bool, value = sizeof(tester<Base, Derived>) == sizeof(Derived)); }; template <typename Base, typename Derived> struct impl<Base, Derived, false> { BOOST_STATIC_CONSTANT(bool, value = false); }; } template <typename Base, typename Derived> struct is_virtual_base_and_derived : is_virtual_base_and_derived_detail::impl<Base, Derived, boost::is_convertible<Derived*, Base*>::value> { }; template <typename T> struct is_virtual_base_and_derived<T, T> { BOOST_STATIC_CONSTANT(bool, value = false); }; -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: Tuesday, July 06, 2004 6:01 PM To: boost@lists.boost.org Subject: [boost] Does anyone have an is_virtual_base_and_derived ? Type traits includes: ::boost::is_base_and_derived<T,U> Does anyone have a version that might be called is_virtual_base_and_derived<B, D> which would return true iff D is derived virtually from B ? Robert Ramey _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (1)
-
SRobb@reflectionsinteractive.com