Chris@16
|
1
|
Chris@16
|
2 #if !defined(BOOST_PP_IS_ITERATING)
|
Chris@16
|
3
|
Chris@16
|
4 ///// header body
|
Chris@16
|
5
|
Chris@16
|
6 #ifndef BOOST_MPL_INHERIT_HPP_INCLUDED
|
Chris@16
|
7 #define BOOST_MPL_INHERIT_HPP_INCLUDED
|
Chris@16
|
8
|
Chris@16
|
9 // Copyright Aleksey Gurtovoy 2001-2004
|
Chris@16
|
10 //
|
Chris@16
|
11 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
12 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
13 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
14 //
|
Chris@16
|
15 // See http://www.boost.org/libs/mpl for documentation.
|
Chris@16
|
16
|
Chris@101
|
17 // $Id$
|
Chris@101
|
18 // $Date$
|
Chris@101
|
19 // $Revision$
|
Chris@16
|
20
|
Chris@16
|
21 #if !defined(BOOST_MPL_PREPROCESSING_MODE)
|
Chris@16
|
22 # include <boost/mpl/empty_base.hpp>
|
Chris@16
|
23 # include <boost/mpl/aux_/na_spec.hpp>
|
Chris@16
|
24 # include <boost/mpl/aux_/lambda_support.hpp>
|
Chris@16
|
25 #endif
|
Chris@16
|
26
|
Chris@16
|
27 #include <boost/mpl/aux_/config/use_preprocessed.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 #if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
|
Chris@16
|
30 && !defined(BOOST_MPL_PREPROCESSING_MODE)
|
Chris@16
|
31
|
Chris@16
|
32 # define BOOST_MPL_PREPROCESSED_HEADER inherit.hpp
|
Chris@16
|
33 # include <boost/mpl/aux_/include_preprocessed.hpp>
|
Chris@16
|
34
|
Chris@16
|
35 #else
|
Chris@16
|
36
|
Chris@16
|
37 # include <boost/mpl/limits/arity.hpp>
|
Chris@16
|
38 # include <boost/mpl/aux_/preprocessor/params.hpp>
|
Chris@16
|
39 # include <boost/mpl/aux_/preprocessor/default_params.hpp>
|
Chris@16
|
40 # include <boost/mpl/aux_/preprocessor/enum.hpp>
|
Chris@16
|
41 # include <boost/mpl/aux_/config/ctps.hpp>
|
Chris@16
|
42 # include <boost/mpl/aux_/config/dtp.hpp>
|
Chris@16
|
43
|
Chris@16
|
44 # include <boost/preprocessor/iterate.hpp>
|
Chris@16
|
45 # include <boost/preprocessor/dec.hpp>
|
Chris@16
|
46 # include <boost/preprocessor/cat.hpp>
|
Chris@16
|
47
|
Chris@16
|
48 namespace boost { namespace mpl {
|
Chris@16
|
49
|
Chris@16
|
50 // 'inherit<T1,T2,..,Tn>' metafunction; returns an unspecified class type
|
Chris@16
|
51 // produced by public derivation from all metafunction's parameters
|
Chris@16
|
52 // (T1,T2,..,Tn), except the parameters of 'empty_base' class type;
|
Chris@16
|
53 // regardless the position and number of 'empty_base' parameters in the
|
Chris@16
|
54 // metafunction's argument list, derivation from them is always a no-op;
|
Chris@16
|
55 // for instance:
|
Chris@16
|
56 // inherit<her>::type == her
|
Chris@16
|
57 // inherit<her,my>::type == struct unspecified : her, my {};
|
Chris@16
|
58 // inherit<empty_base,her>::type == her
|
Chris@16
|
59 // inherit<empty_base,her,empty_base,empty_base>::type == her
|
Chris@16
|
60 // inherit<her,empty_base,my>::type == struct unspecified : her, my {};
|
Chris@16
|
61 // inherit<empty_base,empty_base>::type == empty_base
|
Chris@16
|
62
|
Chris@16
|
63 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
Chris@16
|
64
|
Chris@16
|
65 template<
|
Chris@16
|
66 typename BOOST_MPL_AUX_NA_PARAM(T1)
|
Chris@16
|
67 , typename BOOST_MPL_AUX_NA_PARAM(T2)
|
Chris@16
|
68 >
|
Chris@16
|
69 struct inherit2
|
Chris@16
|
70 : T1, T2
|
Chris@16
|
71 {
|
Chris@16
|
72 typedef inherit2 type;
|
Chris@16
|
73 BOOST_MPL_AUX_LAMBDA_SUPPORT(2, inherit2, (T1,T2))
|
Chris@16
|
74 };
|
Chris@16
|
75
|
Chris@16
|
76 template< typename T1 >
|
Chris@16
|
77 struct inherit2<T1,empty_base>
|
Chris@16
|
78 {
|
Chris@16
|
79 typedef T1 type;
|
Chris@16
|
80 BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2, inherit2, (T1,empty_base))
|
Chris@16
|
81 };
|
Chris@16
|
82
|
Chris@16
|
83 template< typename T2 >
|
Chris@16
|
84 struct inherit2<empty_base,T2>
|
Chris@16
|
85 {
|
Chris@16
|
86 typedef T2 type;
|
Chris@16
|
87 BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2, inherit2, (empty_base,T2))
|
Chris@16
|
88 };
|
Chris@16
|
89
|
Chris@16
|
90 // needed to disambiguate the previous two in case when both
|
Chris@16
|
91 // T1 and T2 == empty_base
|
Chris@16
|
92 template<>
|
Chris@16
|
93 struct inherit2<empty_base,empty_base>
|
Chris@16
|
94 {
|
Chris@16
|
95 typedef empty_base type;
|
Chris@16
|
96 BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2, inherit2, (empty_base,empty_base))
|
Chris@16
|
97 };
|
Chris@16
|
98
|
Chris@16
|
99 #else
|
Chris@16
|
100
|
Chris@16
|
101 namespace aux {
|
Chris@16
|
102
|
Chris@16
|
103 template< bool C1, bool C2 >
|
Chris@16
|
104 struct inherit2_impl
|
Chris@16
|
105 {
|
Chris@16
|
106 template< typename Derived, typename T1, typename T2 > struct result_
|
Chris@16
|
107 : T1, T2
|
Chris@16
|
108 {
|
Chris@16
|
109 typedef Derived type_;
|
Chris@16
|
110 };
|
Chris@16
|
111 };
|
Chris@16
|
112
|
Chris@16
|
113 template<>
|
Chris@16
|
114 struct inherit2_impl<false,true>
|
Chris@16
|
115 {
|
Chris@16
|
116 template< typename Derived, typename T1, typename T2 > struct result_
|
Chris@16
|
117 : T1
|
Chris@16
|
118 {
|
Chris@16
|
119 typedef T1 type_;
|
Chris@16
|
120 };
|
Chris@16
|
121 };
|
Chris@16
|
122
|
Chris@16
|
123 template<>
|
Chris@16
|
124 struct inherit2_impl<true,false>
|
Chris@16
|
125 {
|
Chris@16
|
126 template< typename Derived, typename T1, typename T2 > struct result_
|
Chris@16
|
127 : T2
|
Chris@16
|
128 {
|
Chris@16
|
129 typedef T2 type_;
|
Chris@16
|
130 };
|
Chris@16
|
131 };
|
Chris@16
|
132
|
Chris@16
|
133 template<>
|
Chris@16
|
134 struct inherit2_impl<true,true>
|
Chris@16
|
135 {
|
Chris@16
|
136 template< typename Derived, typename T1, typename T2 > struct result_
|
Chris@16
|
137 {
|
Chris@16
|
138 typedef T1 type_;
|
Chris@16
|
139 };
|
Chris@16
|
140 };
|
Chris@16
|
141
|
Chris@16
|
142 } // namespace aux
|
Chris@16
|
143
|
Chris@16
|
144 template<
|
Chris@16
|
145 typename BOOST_MPL_AUX_NA_PARAM(T1)
|
Chris@16
|
146 , typename BOOST_MPL_AUX_NA_PARAM(T2)
|
Chris@16
|
147 >
|
Chris@16
|
148 struct inherit2
|
Chris@16
|
149 : aux::inherit2_impl<
|
Chris@16
|
150 is_empty_base<T1>::value
|
Chris@16
|
151 , is_empty_base<T2>::value
|
Chris@16
|
152 >::template result_< inherit2<T1,T2>,T1,T2 >
|
Chris@16
|
153 {
|
Chris@16
|
154 typedef typename inherit2::type_ type;
|
Chris@16
|
155 BOOST_MPL_AUX_LAMBDA_SUPPORT(2, inherit2, (T1,T2))
|
Chris@16
|
156 };
|
Chris@16
|
157
|
Chris@16
|
158 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
Chris@16
|
159
|
Chris@16
|
160 BOOST_MPL_AUX_NA_SPEC(2, inherit2)
|
Chris@16
|
161
|
Chris@16
|
162 #define BOOST_PP_ITERATION_PARAMS_1 \
|
Chris@16
|
163 (3,(3, BOOST_MPL_LIMIT_METAFUNCTION_ARITY, <boost/mpl/inherit.hpp>))
|
Chris@16
|
164 #include BOOST_PP_ITERATE()
|
Chris@16
|
165
|
Chris@16
|
166 }}
|
Chris@16
|
167
|
Chris@16
|
168 #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
|
Chris@16
|
169 #endif // BOOST_MPL_INHERIT_HPP_INCLUDED
|
Chris@16
|
170
|
Chris@16
|
171 ///// iteration
|
Chris@16
|
172
|
Chris@16
|
173 #else
|
Chris@16
|
174 #define n_ BOOST_PP_FRAME_ITERATION(1)
|
Chris@16
|
175
|
Chris@16
|
176 template<
|
Chris@16
|
177 BOOST_MPL_PP_DEFAULT_PARAMS(n_, typename T, na)
|
Chris@16
|
178 >
|
Chris@16
|
179 struct BOOST_PP_CAT(inherit,n_)
|
Chris@16
|
180 : inherit2<
|
Chris@16
|
181 typename BOOST_PP_CAT(inherit,BOOST_PP_DEC(n_))<
|
Chris@16
|
182 BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(n_), T)
|
Chris@16
|
183 >::type
|
Chris@16
|
184 , BOOST_PP_CAT(T,n_)
|
Chris@16
|
185 >
|
Chris@16
|
186 {
|
Chris@16
|
187 BOOST_MPL_AUX_LAMBDA_SUPPORT(
|
Chris@16
|
188 n_
|
Chris@16
|
189 , BOOST_PP_CAT(inherit,n_)
|
Chris@16
|
190 , (BOOST_MPL_PP_PARAMS(n_, T))
|
Chris@16
|
191 )
|
Chris@16
|
192 };
|
Chris@16
|
193
|
Chris@16
|
194 BOOST_MPL_AUX_NA_SPEC(n_, BOOST_PP_CAT(inherit,n_))
|
Chris@16
|
195
|
Chris@16
|
196 #if n_ == BOOST_MPL_LIMIT_METAFUNCTION_ARITY
|
Chris@16
|
197 /// primary template
|
Chris@16
|
198 template<
|
Chris@16
|
199 BOOST_MPL_PP_DEFAULT_PARAMS(n_, typename T, empty_base)
|
Chris@16
|
200 >
|
Chris@16
|
201 struct inherit
|
Chris@16
|
202 : BOOST_PP_CAT(inherit,n_)<BOOST_MPL_PP_PARAMS(n_, T)>
|
Chris@16
|
203 {
|
Chris@16
|
204 };
|
Chris@16
|
205
|
Chris@16
|
206 // 'na' specialization
|
Chris@16
|
207 template<>
|
Chris@16
|
208 struct inherit< BOOST_MPL_PP_ENUM(5, na) >
|
Chris@16
|
209 {
|
Chris@16
|
210 template<
|
Chris@16
|
211 #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES)
|
Chris@16
|
212 BOOST_MPL_PP_DEFAULT_PARAMS(n_, typename T, empty_base)
|
Chris@16
|
213 #else
|
Chris@16
|
214 BOOST_MPL_PP_PARAMS(n_, typename T)
|
Chris@16
|
215 #endif
|
Chris@16
|
216 >
|
Chris@16
|
217 struct apply
|
Chris@16
|
218 : inherit< BOOST_MPL_PP_PARAMS(n_, T) >
|
Chris@16
|
219 {
|
Chris@16
|
220 };
|
Chris@16
|
221 };
|
Chris@16
|
222
|
Chris@16
|
223 BOOST_MPL_AUX_NA_SPEC_LAMBDA(n_, inherit)
|
Chris@16
|
224 BOOST_MPL_AUX_NA_SPEC_ARITY(n_, inherit)
|
Chris@16
|
225 BOOST_MPL_AUX_NA_SPEC_TEMPLATE_ARITY(n_, n_, inherit)
|
Chris@16
|
226 #endif
|
Chris@16
|
227
|
Chris@16
|
228 #undef n_
|
Chris@16
|
229 #endif // BOOST_PP_IS_ITERATING
|