summaryrefslogtreecommitdiff
path: root/boost/type_erasure/detail
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2016-10-06 10:33:54 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2016-10-06 10:36:09 +0900
commitd9ec475d945d3035377a0d89ed42e382d8988891 (patch)
tree34aff2cee4b209906243ab5499d61f3edee2982f /boost/type_erasure/detail
parent71d216b90256936a9638f325af9bc69d720e75de (diff)
downloadboost-d9ec475d945d3035377a0d89ed42e382d8988891.tar.gz
boost-d9ec475d945d3035377a0d89ed42e382d8988891.tar.bz2
boost-d9ec475d945d3035377a0d89ed42e382d8988891.zip
Imported Upstream version 1.60.0
Change-Id: Ie709530d6d5841088ceaba025cbe175a4ef43050 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/type_erasure/detail')
-rw-r--r--boost/type_erasure/detail/adapt_to_vtable.hpp38
-rw-r--r--boost/type_erasure/detail/auto_link.hpp38
-rw-r--r--boost/type_erasure/detail/check_map.hpp2
-rw-r--r--boost/type_erasure/detail/dynamic_vtable.hpp172
-rw-r--r--boost/type_erasure/detail/rebind_placeholders.hpp1
-rw-r--r--boost/type_erasure/detail/storage.hpp4
6 files changed, 253 insertions, 2 deletions
diff --git a/boost/type_erasure/detail/adapt_to_vtable.hpp b/boost/type_erasure/detail/adapt_to_vtable.hpp
index 8f90395c74..e58ddc8599 100644
--- a/boost/type_erasure/detail/adapt_to_vtable.hpp
+++ b/boost/type_erasure/detail/adapt_to_vtable.hpp
@@ -35,6 +35,9 @@ namespace boost {
namespace type_erasure {
namespace detail {
+
+template<class T, class Out>
+struct get_placeholders;
template<class T, class Bindings>
struct rebind_placeholders;
@@ -54,6 +57,12 @@ struct rebind_placeholders<vtable_adapter<PrimitiveConcept, Sig>, Bindings>
> type;
};
+template<class PrimitiveConcept, class Sig, class Out>
+struct get_placeholders<vtable_adapter<PrimitiveConcept, Sig>, Out>
+{
+ typedef typename get_placeholders<PrimitiveConcept, Out>::type type;
+};
+
template<class T>
struct replace_param_for_vtable
{
@@ -194,6 +203,17 @@ struct vtable_adapter_impl<PrimitiveConcept, R(T...), R2(U...)>
};
template<class PrimitiveConcept, class... T, class R2, class... U>
+struct vtable_adapter_impl<PrimitiveConcept, ::boost::type_erasure::detail::storage(T...), R2(U...)>
+{
+ typedef ::boost::type_erasure::detail::storage (*type)(T...);
+ static ::boost::type_erasure::detail::storage value(T... arg)
+ {
+ return ::boost::type_erasure::detail::storage(
+ PrimitiveConcept::apply(::boost::type_erasure::detail::extract<U>(std::forward<T>(arg))...));
+ }
+};
+
+template<class PrimitiveConcept, class... T, class R2, class... U>
struct vtable_adapter_impl<PrimitiveConcept, ::boost::type_erasure::detail::storage&(T...), R2(U...)>
{
typedef ::boost::type_erasure::detail::storage (*type)(T...);
@@ -300,6 +320,24 @@ struct vtable_adapter<PrimitiveConcept, R(BOOST_PP_ENUM_PARAMS(N, T))>
template<class PrimitiveConcept
BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)>
+struct vtable_adapter<PrimitiveConcept, ::boost::type_erasure::detail::storage(BOOST_PP_ENUM_PARAMS(N, T))>
+{
+ typedef ::boost::type_erasure::detail::storage (*type)(BOOST_PP_ENUM_PARAMS(N, T));
+ static ::boost::type_erasure::detail::storage value(BOOST_PP_ENUM_BINARY_PARAMS(N, T, arg))
+ {
+ typedef typename ::boost::function_traits<
+ typename ::boost::type_erasure::detail::get_signature<
+ PrimitiveConcept
+ >::type
+ > traits;
+ return ::boost::type_erasure::detail::storage(
+ PrimitiveConcept::apply(
+ BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_EXTRACT, ~)));
+ }
+};
+
+template<class PrimitiveConcept
+ BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)>
struct vtable_adapter<PrimitiveConcept, ::boost::type_erasure::detail::storage&(BOOST_PP_ENUM_PARAMS(N, T))>
{
typedef ::boost::type_erasure::detail::storage (*type)(BOOST_PP_ENUM_PARAMS(N, T));
diff --git a/boost/type_erasure/detail/auto_link.hpp b/boost/type_erasure/detail/auto_link.hpp
new file mode 100644
index 0000000000..4f4392044b
--- /dev/null
+++ b/boost/type_erasure/detail/auto_link.hpp
@@ -0,0 +1,38 @@
+// Boost.TypeErasure library
+//
+// Copyright 2015 Steven Watanabe
+//
+// Distributed under the Boost Software License Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// $Id$
+
+#ifndef BOOST_TYPE_ERASURE_DETAIL_AUTO_LINK_HPP_INCLUDED
+#define BOOST_TYPE_ERASURE_DETAIL_AUTO_LINK_HPP_INCLUDED
+
+#include <boost/config.hpp>
+
+#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_TYPE_ERASURE_DYN_LINK)
+ #ifdef BOOST_TYPE_ERASURE_SOURCE
+ #define BOOST_TYPE_ERASURE_DECL BOOST_SYMBOL_EXPORT
+ #else
+ #define BOOST_TYPE_ERASURE_DECL BOOST_SYMBOL_IMPORT
+ #endif
+#else
+ #define BOOST_TYPE_ERASURE_DECL
+#endif
+
+#if !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_TYPE_ERASURE_NO_LIB) && !defined(BOOST_TYPE_ERASURE_SOURCE)
+
+ #define BOOST_LIB_NAME boost_type_erasure
+
+ #if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_TYPE_ERASURE_DYN_LINK)
+ #define BOOST_DYN_LINK
+ #endif
+
+ #include <boost/config/auto_link.hpp>
+
+#endif
+
+#endif
diff --git a/boost/type_erasure/detail/check_map.hpp b/boost/type_erasure/detail/check_map.hpp
index 83435b6479..a51c95deb0 100644
--- a/boost/type_erasure/detail/check_map.hpp
+++ b/boost/type_erasure/detail/check_map.hpp
@@ -17,9 +17,11 @@
#include <boost/mpl/set.hpp>
#include <boost/mpl/has_key.hpp>
#include <boost/mpl/find_if.hpp>
+#include <boost/mpl/fold.hpp>
#include <boost/mpl/end.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_erasure/detail/get_placeholders.hpp>
+#include <boost/type_erasure/detail/normalize.hpp>
#include <boost/type_erasure/deduced.hpp>
#include <boost/type_erasure/static_binding.hpp>
diff --git a/boost/type_erasure/detail/dynamic_vtable.hpp b/boost/type_erasure/detail/dynamic_vtable.hpp
new file mode 100644
index 0000000000..9e014ed61b
--- /dev/null
+++ b/boost/type_erasure/detail/dynamic_vtable.hpp
@@ -0,0 +1,172 @@
+// Boost.TypeErasure library
+//
+// Copyright 2015 Steven Watanabe
+//
+// Distributed under the Boost Software License Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// $Id$
+
+#ifndef BOOST_TYPE_ERASURE_DETAIL_DYNAMIC_VTABLE_HPP_INCLUDED
+#define BOOST_TYPE_ERASURE_DETAIL_DYNAMIC_VTABLE_HPP_INCLUDED
+
+#include <boost/type_erasure/detail/get_placeholders.hpp>
+#include <boost/type_erasure/detail/rebind_placeholders.hpp>
+#include <boost/type_erasure/detail/normalize.hpp>
+#include <boost/type_erasure/detail/adapt_to_vtable.hpp>
+#include <boost/type_erasure/detail/vtable.hpp>
+#include <boost/type_erasure/static_binding.hpp>
+#include <boost/type_erasure/register_binding.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/at.hpp>
+#include <boost/mpl/set.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/index_of.hpp>
+#include <typeinfo>
+
+namespace boost {
+namespace type_erasure {
+namespace detail {
+
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_CONSTEXPR) && !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
+
+template<class P>
+struct dynamic_binding_impl
+{
+ const std::type_info * type;
+};
+
+template<class Table>
+struct append_to_key {
+ template<class P>
+ void operator()(P) {
+ key->push_back(static_cast<const dynamic_binding_impl<P>*>(table)->type);
+ }
+ const Table * table;
+ key_type * key;
+};
+
+template<class... P>
+struct dynamic_vtable : dynamic_binding_impl<P>... {
+ dynamic_vtable() = default;
+ template<class... T>
+ constexpr dynamic_vtable(T* ...t) : dynamic_binding_impl<P>{t}... {}
+ template<class F>
+ typename F::type lookup(F*) const {
+ key_type key;
+ typedef typename ::boost::type_erasure::detail::get_placeholders<F, ::boost::mpl::set0<> >::type placeholders;
+ typedef typename ::boost::mpl::fold<
+ placeholders,
+ ::boost::mpl::map0<>,
+ ::boost::type_erasure::detail::counting_map_appender
+ >::type placeholder_map;
+ key.push_back(&typeid(typename ::boost::type_erasure::detail::rebind_placeholders<F, placeholder_map>::type));
+ ::boost::mpl::for_each<placeholders>(append_to_key<dynamic_vtable>{this, &key});
+ return reinterpret_cast<typename F::type>(lookup_function_impl(key));
+ }
+ template<class Bindings>
+ void init() {
+ *this = dynamic_vtable(&typeid(typename boost::mpl::at<Bindings, P>::type)...);
+ }
+ template<class Bindings, class Src>
+ void convert_from(const Src& src) {
+ *this = dynamic_vtable(
+ (&src.lookup((::boost::type_erasure::typeid_<typename ::boost::mpl::at<Bindings, P>::type>*)0)())...);
+ }
+};
+
+template<class L>
+struct make_dynamic_vtable_impl;
+
+template<class... P>
+struct make_dynamic_vtable_impl<stored_arg_pack<P...> >
+{
+ typedef dynamic_vtable<P...> type;
+};
+
+template<class PlaceholderList>
+struct make_dynamic_vtable
+ : make_dynamic_vtable_impl<typename make_arg_pack<PlaceholderList>::type>
+{};
+
+#else
+
+template<class Bindings>
+struct dynamic_vtable_initializer
+{
+ dynamic_vtable_initializer(const std::type_info**& ptr) : types(&ptr) {}
+ template<class P>
+ void operator()(P)
+ {
+ *(*types)++ = &typeid(typename ::boost::mpl::at<Bindings, P>::type);
+ }
+ const ::std::type_info*** types;
+};
+
+template<class Placeholders>
+struct dynamic_vtable
+{
+ const ::std::type_info * types[(::boost::mpl::size<Placeholders>::value)];
+ struct append_to_key
+ {
+ append_to_key(const std::type_info * const * t, key_type* k) : types(t), key(k) {}
+ template<class P>
+ void operator()(P)
+ {
+ key->push_back(types[(::boost::mpl::index_of<Placeholders, P>::type::value)]);
+ }
+ const std::type_info * const * types;
+ key_type * key;
+ };
+ template<class F>
+ typename F::type lookup(F*) const {
+ key_type key;
+ typedef typename ::boost::type_erasure::detail::get_placeholders<F, ::boost::mpl::set0<> >::type placeholders;
+ typedef typename ::boost::mpl::fold<
+ placeholders,
+ ::boost::mpl::map0<>,
+ ::boost::type_erasure::detail::counting_map_appender
+ >::type placeholder_map;
+ key.push_back(&typeid(typename ::boost::type_erasure::detail::rebind_placeholders<F, placeholder_map>::type));
+ ::boost::mpl::for_each<placeholders>(append_to_key(types, &key));
+ return reinterpret_cast<typename F::type>(lookup_function_impl(key));
+ }
+ template<class Bindings>
+ void init()
+ {
+ const std::type_info* ptr = types;
+ ::boost::mpl::for_each<Placeholders>(dynamic_vtable_initializer<Bindings>(ptr));
+ }
+ template<class Bindings, class Src>
+ struct converter
+ {
+ converter(const std::type_info**& t, const Src& s) : types(&t), src(&s) {}
+ template<class P>
+ void operator()(P)
+ {
+ *(*types)++ = &src->lookup((::boost::type_erasure::typeid_<typename ::boost::mpl::at<Bindings, P>::type>*)0)();
+ }
+ const std::type_info*** types;
+ const Src * src;
+ };
+ template<class Bindings, class Src>
+ void convert_from(const Src& src) {
+ const ::std::type_info** ptr = types;
+ ::boost::mpl::for_each<Placeholders>(converter<Bindings, Src>(ptr, src));
+ }
+};
+
+template<class Placeholders>
+struct make_dynamic_vtable
+{
+ typedef dynamic_vtable<Placeholders> type;
+};
+
+#endif
+
+}
+}
+}
+
+#endif
diff --git a/boost/type_erasure/detail/rebind_placeholders.hpp b/boost/type_erasure/detail/rebind_placeholders.hpp
index a9cd546737..d93d429c5d 100644
--- a/boost/type_erasure/detail/rebind_placeholders.hpp
+++ b/boost/type_erasure/detail/rebind_placeholders.hpp
@@ -18,6 +18,7 @@
#include <boost/mpl/at.hpp>
#include <boost/mpl/has_key.hpp>
#include <boost/mpl/not.hpp>
+#include <boost/mpl/or.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
diff --git a/boost/type_erasure/detail/storage.hpp b/boost/type_erasure/detail/storage.hpp
index 658a9fedca..8f8bf865ea 100644
--- a/boost/type_erasure/detail/storage.hpp
+++ b/boost/type_erasure/detail/storage.hpp
@@ -37,11 +37,11 @@ struct storage
storage(storage&& other) : data(other.data) {}
storage& operator=(const storage& other) { data = other.data; return *this; }
template<class T>
- storage(T&& arg) : data(new typename remove_cv<
+ explicit storage(T&& arg) : data(new typename remove_cv<
typename remove_reference<T>::type>::type(std::forward<T>(arg))) {}
#else
template<class T>
- storage(const T& arg) : data(new T(arg)) {}
+ explicit storage(const T& arg) : data(new T(arg)) {}
#endif
void* data;
};