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 #if !defined(BOOST_PP_IS_ITERATING)
13 #ifndef BOOST_TYPE_ERASURE_DETAIL_EXTRACT_CONCEPT_HPP_INCLUDED
14 #define BOOST_TYPE_ERASURE_DETAIL_EXTRACT_CONCEPT_HPP_INCLUDED
16 #include <boost/mpl/eval_if.hpp>
17 #include <boost/mpl/identity.hpp>
18 #include <boost/type_traits/remove_cv.hpp>
19 #include <boost/type_traits/remove_reference.hpp>
20 #include <boost/preprocessor/cat.hpp>
21 #include <boost/preprocessor/inc.hpp>
22 #include <boost/preprocessor/iteration/iterate.hpp>
23 #include <boost/preprocessor/repetition/repeat.hpp>
24 #include <boost/preprocessor/repetition/enum_params.hpp>
25 #include <boost/type_erasure/is_placeholder.hpp>
26 #include <boost/type_erasure/concept_of.hpp>
27 #include <boost/type_erasure/config.hpp>
30 namespace type_erasure {
33 template<class T, class U>
34 struct combine_concepts;
37 struct combine_concepts<T, T> { typedef T type; };
39 struct combine_concepts<T, void> { typedef T type; };
41 struct combine_concepts<void, T> { typedef T type; };
43 struct combine_concepts<void, void> { typedef void type; };
45 #ifdef BOOST_TYPE_ERASURE_USE_MP11
47 template<class T, class U>
48 using combine_concepts_t = typename ::boost::type_erasure::detail::combine_concepts<T, U>::type;
50 template<class T, class U>
51 using extract_concept_or_void =
52 ::boost::mp11::mp_eval_if_c<
53 !::boost::type_erasure::is_placeholder<
55 ::boost::remove_reference_t<T>
59 ::boost::type_erasure::concept_of_t, U
62 template<class L1, class L2>
63 using extract_concept_t =
64 ::boost::mp11::mp_fold<
65 ::boost::mp11::mp_transform< ::boost::type_erasure::detail::extract_concept_or_void, L1, L2>,
67 ::boost::type_erasure::detail::combine_concepts_t
72 template<class T, class U>
73 struct maybe_extract_concept
75 typedef typename ::boost::mpl::eval_if<
76 ::boost::type_erasure::is_placeholder<
77 typename ::boost::remove_cv<
78 typename ::boost::remove_reference<T>::type
81 ::boost::type_erasure::concept_of<typename ::boost::remove_reference<U>::type>,
82 ::boost::mpl::identity<void>
86 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
88 template<class Args, class... U>
89 struct extract_concept;
91 template<class R, class T0, class... T, class U0, class... U>
92 struct extract_concept<R(T0, T...), U0, U...>
94 typedef typename ::boost::type_erasure::detail::combine_concepts<
95 typename ::boost::type_erasure::detail::maybe_extract_concept<
98 typename ::boost::type_erasure::detail::extract_concept<
106 struct extract_concept<void()>
113 #define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/extract_concept.hpp>
114 #define BOOST_PP_ITERATION_LIMITS (1, BOOST_TYPE_ERASURE_MAX_ARITY)
115 #include BOOST_PP_ITERATE()
129 #define N BOOST_PP_ITERATION()
131 #define BOOST_TYPE_ERASURE_EXTRACT_CONCEPT(z, n, data) \
132 typedef typename ::boost::type_erasure::detail::combine_concepts< \
133 typename ::boost::type_erasure::detail::maybe_extract_concept< \
134 BOOST_PP_CAT(T, n), BOOST_PP_CAT(U, n) \
136 BOOST_PP_CAT(concept, n) \
137 >::type BOOST_PP_CAT(concept, BOOST_PP_INC(n));
140 BOOST_PP_ENUM_PARAMS(N, class T),
141 BOOST_PP_ENUM_PARAMS(N, class U)>
142 struct BOOST_PP_CAT(extract_concept, N)
144 typedef void concept0;
146 BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_EXTRACT_CONCEPT, ~)
148 typedef BOOST_PP_CAT(concept, N) type;
151 #undef BOOST_TYPE_ERASURE_EXTRACT_CONCEPT