]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/type_index/runtime_cast/detail/runtime_cast_impl.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / type_index / runtime_cast / detail / runtime_cast_impl.hpp
1 //
2 // Copyright (c) Chris Glover, 2016.
3 //
4 //
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)
7 //
8
9 #ifndef BOOST_TYPE_INDEX_RUNTIME_CAST_DETAIL_RUNTIME_CAST_IMPL_HPP
10 #define BOOST_TYPE_INDEX_RUNTIME_CAST_DETAIL_RUNTIME_CAST_IMPL_HPP
11
12 /// \file runtime_cast_impl.hpp
13 /// \brief Contains the overload of boost::typeindex::runtime_cast for
14 /// pointer types.
15 ///
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.
19
20 #include <boost/type_index.hpp>
21 #include <boost/type_traits/integral_constant.hpp>
22
23 #ifdef BOOST_HAS_PRAGMA_ONCE
24 # pragma once
25 #endif
26
27 namespace boost { namespace typeindex {
28
29 namespace detail {
30
31 template<typename T, typename U>
32 T* runtime_cast_impl(U* u, boost::true_type) BOOST_NOEXCEPT {
33 return u;
34 }
35
36 template<typename T, typename U>
37 T const* runtime_cast_impl(U const* u, boost::true_type) BOOST_NOEXCEPT {
38 return u;
39 }
40
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>())
45 ));
46 }
47
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>()));
51 }
52
53 } // namespace detail
54
55 }} // namespace boost::typeindex
56
57 #endif // BOOST_TYPE_INDEX_RUNTIME_CAST_DETAIL_RUNTIME_CAST_IMPL_HPP