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