123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #ifndef BOOST_POLYMORPHIC_CAST_HPP
- #define BOOST_POLYMORPHIC_CAST_HPP
- #include <boost/config.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- # pragma once
- #endif
- # include <boost/assert.hpp>
- # include <boost/throw_exception.hpp>
- # include <memory> // std::addressof
- # include <typeinfo>
- # include <type_traits>
- namespace boost
- {
-
-
-
- template <class Target, class Source>
- inline Target polymorphic_cast(Source* x)
- {
- Target tmp = dynamic_cast<Target>(x);
- if ( tmp == 0 ) boost::throw_exception( std::bad_cast() );
- return tmp;
- }
-
-
-
-
-
-
- template <class Target, class Source>
- inline Target polymorphic_downcast(Source* x)
- {
- BOOST_ASSERT( dynamic_cast<Target>(x) == x );
- return static_cast<Target>(x);
- }
-
-
-
-
-
-
- template <class Target, class Source>
- inline typename std::enable_if<
- std::is_reference<Target>::value, Target
- >::type polymorphic_downcast(Source& x)
- {
- typedef typename std::remove_reference<Target>::type* target_pointer_type;
- return *boost::polymorphic_downcast<target_pointer_type>(
- std::addressof(x)
- );
- }
- }
- #endif
|