1 // Boost.TypeErasure library
3 // Copyright 2011 Steven Watanabe
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)
11 #ifndef BOOST_TYPE_ERASURE_BUILTIN_HPP_INCLUDED
12 #define BOOST_TYPE_ERASURE_BUILTIN_HPP_INCLUDED
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>
22 namespace type_erasure {
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.
29 * \note The @ref destructible concept rarely needs to
30 * be specified explicitly, because it is included in
31 * the @ref copy_constructible concept.
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.
37 template<class T = _self>
41 typedef void (*type)(detail::storage&);
43 static void value(detail::storage& arg)
45 delete static_cast<T*>(arg.data);
48 static void apply(detail::storage& arg)
50 delete static_cast<T*>(arg.data);
55 * The @ref copy_constructible concept allows objects to
56 * be copied and destroyed.
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.
62 template<class T = _self>
63 struct copy_constructible :
64 ::boost::mpl::vector<constructible<T(const T&)>, destructible<T> >
68 * Enables assignment of @ref any types.
70 template<class T = _self, class U = T>
73 static void apply(T& dst, const U& src) { dst = src; }
77 template<class T, class U, class Base>
78 struct concept_interface<assignable<T, U>, Base, T> : Base
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)
89 * Enables runtime type information. This is required
90 * if you want to use \any_cast or \typeid_of.
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,
99 template<class T = _self>
103 typedef const std::type_info& (*type)();
105 static const std::type_info& value()
110 static const std::type_info& apply()
119 struct get_null_vtable_entry;
122 struct get_null_vtable_entry< ::boost::type_erasure::typeid_<T> >
124 typedef typeid_<void> type;
127 struct null_destroy {
128 static void value(::boost::type_erasure::detail::storage&) {}
132 struct get_null_vtable_entry< ::boost::type_erasure::destructible<T> >
134 typedef ::boost::type_erasure::detail::null_destroy type;