--- /usr/include/boost/cast.hpp 2014-03-01 06:51:57.000000000 +0100 +++ /home/k1000/virtual/cast.hpp 2014-03-20 17:25:03.689869142 +0100 @@ -49,6 +49,9 @@ # include # include # include +# include +# include +# include // It has been demonstrated numerous times that MSVC 6.0 fails silently at link // time if you use a template function which has template parameters that don't @@ -82,6 +85,25 @@ // polymorphic_downcast ----------------------------------------------------// + namespace detail + { + + template + struct polymorphic_static_downcast + { + static Out eval(In* in) + { return static_cast( in ); } + }; + + template + struct polymorphic_dynamic_downcast + { + static Out eval(In* in) + { return dynamic_cast( in ); } + }; + + } + // BOOST_ASSERT() checked polymorphic downcast. Crosscasts prohibited. // WARNING: Because this cast uses BOOST_ASSERT(), it violates @@ -95,7 +117,15 @@ inline Target polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET) { BOOST_ASSERT( dynamic_cast(x) == x ); // detect logic error - return static_cast(x); + + typedef typename boost::remove_pointer::type out_class; + typedef boost::is_virtual_base_of dyn; + typedef typename boost::mpl::if_ + , polymorphic_static_downcast + >::type impl; + + return impl::eval(x); } # undef BOOST_EXPLICIT_DEFAULT_TARGET