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 #if !defined(BOOST_PP_IS_ITERATING)
12 
13 #ifndef BOOST_TYPE_ERASURE_DETAIL_EXTRACT_CONCEPT_HPP_INCLUDED
14 #define BOOST_TYPE_ERASURE_DETAIL_EXTRACT_CONCEPT_HPP_INCLUDED
15 
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>
28 
29 namespace boost {
30 namespace type_erasure {
31 namespace detail {
32 
33 template<class T, class U>
34 struct combine_concepts;
35 
36 template<class T>
37 struct combine_concepts<T, T> { typedef T type; };
38 template<class T>
39 struct combine_concepts<T, void> { typedef T type; };
40 template<class T>
41 struct combine_concepts<void, T> { typedef T type; };
42 template<>
43 struct combine_concepts<void, void> { typedef void type; };
44 
45 template<class T, class U>
46 struct maybe_extract_concept
47 {
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
52             >::type
53         >,
54         ::boost::type_erasure::concept_of<typename ::boost::remove_reference<U>::type>,
55         ::boost::mpl::identity<void>
56     >::type type;
57 };
58 
59 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
60 
61 template<class Args, class... U>
62 struct extract_concept;
63 
64 template<class R, class T0, class... T, class U0, class... U>
65 struct extract_concept<R(T0, T...), U0, U...>
66 {
67     typedef typename ::boost::type_erasure::detail::combine_concepts<
68         typename ::boost::type_erasure::detail::maybe_extract_concept<
69             T0, U0
70         >::type,
71         typename ::boost::type_erasure::detail::extract_concept<
72             void(T...),
73             U...
74         >::type
75     >::type type;
76 };
77 
78 template<>
79 struct extract_concept<void()>
80 {
81     typedef void type;
82 };
83 
84 #else
85 //#endif
86 
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()
90 
91 #endif
92 
93 }
94 }
95 }
96 
97 #endif
98 
99 #else
100 
101 #define N BOOST_PP_ITERATION()
102 
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)                      \
107         >::type,                                                        \
108         BOOST_PP_CAT(concept, n)                                        \
109     >::type BOOST_PP_CAT(concept, BOOST_PP_INC(n));
110 
111 template<
112     BOOST_PP_ENUM_PARAMS(N, class T),
113     BOOST_PP_ENUM_PARAMS(N, class U)>
BOOST_PP_CAT(extract_concept,N)114 struct BOOST_PP_CAT(extract_concept, N)
115 {
116     typedef void concept0;
117 
118     BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_EXTRACT_CONCEPT, ~)
119 
120     typedef BOOST_PP_CAT(concept, N) type;
121 };
122 
123 #undef BOOST_TYPE_ERASURE_EXTRACT_CONCEPT
124 #undef N
125 
126 #endif
127