]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/type_erasure/builtin.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / type_erasure / builtin.hpp
CommitLineData
7c673cae
FG
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
21namespace boost {
22namespace 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 */
37template<class T = _self>
38struct 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 */
62template<class T = _self>
63struct copy_constructible :
64 ::boost::mpl::vector<constructible<T(const T&)>, destructible<T> >
65{};
66
67/**
68 * Enables assignment of @ref any types.
69 */
70template<class T = _self, class U = T>
71struct assignable
72{
73 static void apply(T& dst, const U& src) { dst = src; }
74};
75
76/** INTERNAL ONLY */
77template<class T, class U, class Base>
78struct 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 */
99template<class T = _self>
100struct 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
116namespace detail {
117
118template<class C>
119struct get_null_vtable_entry;
120
121template<class T>
122struct get_null_vtable_entry< ::boost::type_erasure::typeid_<T> >
123{
124 typedef typeid_<void> type;
125};
126
127struct null_destroy {
128 static void value(::boost::type_erasure::detail::storage&) {}
129};
130
131template<class T>
132struct 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