Add polymorphic_pointer_cast

This commit is contained in:
Antony Polukhin
2014-11-10 15:02:20 +04:00
parent 6199649ae2
commit 00b6a53f7e
3 changed files with 113 additions and 11 deletions
+12 -1
View File
@@ -1,5 +1,5 @@
// boost polymorphic_pointer_cast.hpp header file ----------------------------------------------//
// (C) Copyright Boris Rasin 2014.
// (C) Copyright Boris Rasin and Antony Polukhin 2014.
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -61,6 +61,17 @@ namespace boost
return static_pointer_cast<Target> (x);
}
template <typename Target, typename Source>
inline typename detail::static_pointer_cast_result<Target, Source>::type
polymorphic_pointer_cast (const Source& x)
{
typename detail::static_pointer_cast_result<Target, Source>::type tmp
= dynamic_pointer_cast<Target> (x);
if ( !tmp ) boost::throw_exception( std::bad_cast() );
return tmp;
}
} // namespace boost
#endif // BOOST_CONVERSION_POLYMORPHIC_POINTER_CAST_HPP