2 // Copyright (c) Chris Glover, 2016.
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_TYPE_INDEX_RUNTIME_CAST_DETAIL_RUNTIME_CAST_IMPL_HPP
10 #define BOOST_TYPE_INDEX_RUNTIME_CAST_DETAIL_RUNTIME_CAST_IMPL_HPP
12 /// \file runtime_cast_impl.hpp
13 /// \brief Contains the overload of boost::typeindex::runtime_cast for
16 /// boost::typeindex::runtime_cast can be used to emulate dynamic_cast
17 /// functionality on platorms that don't provide it or should the user
18 /// desire opt in functionality instead of enabling it system wide.
20 #include <boost/type_index.hpp>
21 #include <boost/type_traits/integral_constant.hpp>
23 #ifdef BOOST_HAS_PRAGMA_ONCE
27 namespace boost { namespace typeindex {
31 template<typename T, typename U>
32 T* runtime_cast_impl(U* u, boost::true_type) BOOST_NOEXCEPT {
36 template<typename T, typename U>
37 T const* runtime_cast_impl(U const* u, boost::true_type) BOOST_NOEXCEPT {
41 template<typename T, typename U>
42 T* runtime_cast_impl(U* u, boost::false_type) BOOST_NOEXCEPT {
43 return const_cast<T*>(static_cast<T const*>(
44 u->boost_type_index_find_instance_(boost::typeindex::type_id<T>())
48 template<typename T, typename U>
49 T const* runtime_cast_impl(U const* u, boost::false_type) BOOST_NOEXCEPT {
50 return static_cast<T const*>(u->boost_type_index_find_instance_(boost::typeindex::type_id<T>()));
55 }} // namespace boost::typeindex
57 #endif // BOOST_TYPE_INDEX_RUNTIME_CAST_DETAIL_RUNTIME_CAST_IMPL_HPP