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 template<class T, class U>
46 struct maybe_extract_concept
48 typedef typename ::boost::mpl::eval_if<
49 ::boost::type_erasure::is_placeholder<
50 typename ::boost::remove_cv<
51 typename ::boost::remove_reference<T>::type
54 ::boost::type_erasure::concept_of<typename ::boost::remove_reference<U>::type>,
55 ::boost::mpl::identity<void>
59 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
61 template<class Args, class... U>
62 struct extract_concept;
64 template<class R, class T0, class... T, class U0, class... U>
65 struct extract_concept<R(T0, T...), U0, U...>
67 typedef typename ::boost::type_erasure::detail::combine_concepts<
68 typename ::boost::type_erasure::detail::maybe_extract_concept<
71 typename ::boost::type_erasure::detail::extract_concept<
79 struct extract_concept<void()>
87 #define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/extract_concept.hpp>
88 #define BOOST_PP_ITERATION_LIMITS (1, BOOST_TYPE_ERASURE_MAX_ARITY)
89 #include BOOST_PP_ITERATE()
101 #define N BOOST_PP_ITERATION()
103 #define BOOST_TYPE_ERASURE_EXTRACT_CONCEPT(z, n, data) \
104 typedef typename ::boost::type_erasure::detail::combine_concepts< \
105 typename ::boost::type_erasure::detail::maybe_extract_concept< \
106 BOOST_PP_CAT(T, n), BOOST_PP_CAT(U, n) \
108 BOOST_PP_CAT(concept, n) \
109 >::type BOOST_PP_CAT(concept, BOOST_PP_INC(n));
112 BOOST_PP_ENUM_PARAMS(N, class T),
113 BOOST_PP_ENUM_PARAMS(N, class U)>
114 struct BOOST_PP_CAT(extract_concept, N)
116 typedef void concept0;
118 BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_EXTRACT_CONCEPT, ~)
120 typedef BOOST_PP_CAT(concept, N) type;
123 #undef BOOST_TYPE_ERASURE_EXTRACT_CONCEPT