]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_erasure/include/boost/type_erasure/builtin.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / type_erasure / include / boost / type_erasure / builtin.hpp
1 // Boost.TypeErasure library
2 //
3 // Copyright 2011 Steven Watanabe
4 //
5 // Distributed under the Boost Software License Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // $Id$
10
11 #ifndef BOOST_TYPE_ERASURE_BUILTIN_HPP_INCLUDED
12 #define BOOST_TYPE_ERASURE_BUILTIN_HPP_INCLUDED
13
14 #include <boost/mpl/vector.hpp>
15 #include <boost/type_erasure/detail/storage.hpp>
16 #include <boost/type_erasure/placeholder.hpp>
17 #include <boost/type_erasure/constructible.hpp>
18 #include <boost/type_erasure/rebind_any.hpp>
19 #include <typeinfo>
20
21 namespace boost {
22 namespace type_erasure {
23
24 /**
25 * The @ref destructible concept enables forwarding to
26 * the destructor of the contained type. This is required
27 * whenever an @ref any is created by value.
28 *
29 * \note The @ref destructible concept rarely needs to
30 * be specified explicitly, because it is included in
31 * the @ref copy_constructible concept.
32 *
33 * \note @ref destructible may not be specialized and
34 * may not be passed to \call as it depends on the
35 * implementation details of @ref any.
36 */
37 template<class T = _self>
38 struct destructible
39 {
40 /** INTERNAL ONLY */
41 typedef void (*type)(detail::storage&);
42 /** INTERNAL ONLY */
43 static void value(detail::storage& arg)
44 {
45 delete static_cast<T*>(arg.data);
46 }
47 /** INTERNAL ONLY */
48 static void apply(detail::storage& arg)
49 {
50 delete static_cast<T*>(arg.data);
51 }
52 };
53
54 /**
55 * The @ref copy_constructible concept allows objects to
56 * be copied and destroyed.
57 *
58 * \note This concept is defined to match C++ 2003,
59 * [lib.copyconstructible]. It is not equivalent to
60 * the concept of the same name in C++11.
61 */
62 template<class T = _self>
63 struct copy_constructible :
64 ::boost::mpl::vector<constructible<T(const T&)>, destructible<T> >
65 {};
66
67 /**
68 * Enables assignment of @ref any types.
69 */
70 template<class T = _self, class U = T>
71 struct assignable
72 {
73 static void apply(T& dst, const U& src) { dst = src; }
74 };
75
76 /** INTERNAL ONLY */
77 template<class T, class U, class Base>
78 struct concept_interface<assignable<T, U>, Base, T> : Base
79 {
80 using Base::_boost_type_erasure_deduce_assign;
81 assignable<T, U>* _boost_type_erasure_deduce_assign(
82 typename ::boost::type_erasure::rebind_any<Base, const U&>::type)
83 {
84 return 0;
85 }
86 };
87
88 /**
89 * Enables runtime type information. This is required
90 * if you want to use \any_cast or \typeid_of.
91 *
92 * \note @ref typeid_ cannot be specialized because several
93 * library components including \any_cast would not work
94 * correctly if its behavior changed. There is no need
95 * to specialize it anyway, since it works for all types.
96 * @ref typeid_ also cannot be passed to \call. To access it,
97 * use \typeid_of.
98 */
99 template<class T = _self>
100 struct typeid_
101 {
102 /** INTERNAL ONLY */
103 typedef const std::type_info& (*type)();
104 /** INTERNAL ONLY */
105 static const std::type_info& value()
106 {
107 return typeid(T);
108 }
109 /** INTERNAL ONLY */
110 static const std::type_info& apply()
111 {
112 return typeid(T);
113 }
114 };
115
116 namespace detail {
117
118 template<class C>
119 struct get_null_vtable_entry;
120
121 template<class T>
122 struct get_null_vtable_entry< ::boost::type_erasure::typeid_<T> >
123 {
124 typedef typeid_<void> type;
125 };
126
127 struct null_destroy {
128 static void value(::boost::type_erasure::detail::storage&) {}
129 };
130
131 template<class T>
132 struct get_null_vtable_entry< ::boost::type_erasure::destructible<T> >
133 {
134 typedef ::boost::type_erasure::detail::null_destroy type;
135 };
136
137 }
138
139 }
140 }
141
142 #endif