First public contribution.
2 #if !defined(BOOST_PP_IS_ITERATING)
6 #ifndef BOOST_MPL_INHERIT_HPP_INCLUDED
7 #define BOOST_MPL_INHERIT_HPP_INCLUDED
9 // Copyright Aleksey Gurtovoy 2001-2004
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)
15 // See http://www.boost.org/libs/mpl for documentation.
17 // $Source: /cvsroot/boost/boost/boost/mpl/inherit.hpp,v $
18 // $Date: 2004/09/02 15:40:41 $
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>
27 #include <boost/mpl/aux_/config/use_preprocessed.hpp>
29 #if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
30 && !defined(BOOST_MPL_PREPROCESSING_MODE)
32 # define BOOST_MPL_PREPROCESSED_HEADER inherit.hpp
33 # include <boost/mpl/aux_/include_preprocessed.hpp>
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>
44 # include <boost/preprocessor/iterate.hpp>
45 # include <boost/preprocessor/dec.hpp>
46 # include <boost/preprocessor/cat.hpp>
48 namespace boost { namespace mpl {
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;
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
63 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
66 typename BOOST_MPL_AUX_NA_PARAM(T1)
67 , typename BOOST_MPL_AUX_NA_PARAM(T2)
72 typedef inherit2 type;
73 BOOST_MPL_AUX_LAMBDA_SUPPORT(2, inherit2, (T1,T2))
76 template< typename T1 >
77 struct inherit2<T1,empty_base>
80 BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2, inherit2, (T1,empty_base))
83 template< typename T2 >
84 struct inherit2<empty_base,T2>
87 BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2, inherit2, (empty_base,T2))
90 // needed to disambiguate the previous two in case when both
91 // T1 and T2 == empty_base
93 struct inherit2<empty_base,empty_base>
95 typedef empty_base type;
96 BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2, inherit2, (empty_base,empty_base))
103 template< bool C1, bool C2 >
106 template< typename Derived, typename T1, typename T2 > struct result_
109 typedef Derived type_;
114 struct inherit2_impl<false,true>
116 template< typename Derived, typename T1, typename T2 > struct result_
124 struct inherit2_impl<true,false>
126 template< typename Derived, typename T1, typename T2 > struct result_
134 struct inherit2_impl<true,true>
136 template< typename Derived, typename T1, typename T2 > struct result_
145 typename BOOST_MPL_AUX_NA_PARAM(T1)
146 , typename BOOST_MPL_AUX_NA_PARAM(T2)
149 : aux::inherit2_impl<
150 is_empty_base<T1>::value
151 , is_empty_base<T2>::value
152 >::template result_< inherit2<T1,T2>,T1,T2 >
154 typedef typename inherit2::type_ type;
155 BOOST_MPL_AUX_LAMBDA_SUPPORT(2, inherit2, (T1,T2))
158 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
160 BOOST_MPL_AUX_NA_SPEC(2, inherit2)
162 #define BOOST_PP_ITERATION_PARAMS_1 \
163 (3,(3, BOOST_MPL_LIMIT_METAFUNCTION_ARITY, <boost/mpl/inherit.hpp>))
164 #include BOOST_PP_ITERATE()
168 #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
169 #endif // BOOST_MPL_INHERIT_HPP_INCLUDED
174 #define n_ BOOST_PP_FRAME_ITERATION(1)
177 BOOST_MPL_PP_DEFAULT_PARAMS(n_, typename T, na)
179 struct BOOST_PP_CAT(inherit,n_)
181 typename BOOST_PP_CAT(inherit,BOOST_PP_DEC(n_))<
182 BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(n_), T)
187 BOOST_MPL_AUX_LAMBDA_SUPPORT(
189 , BOOST_PP_CAT(inherit,n_)
190 , (BOOST_MPL_PP_PARAMS(n_, T))
194 BOOST_MPL_AUX_NA_SPEC(n_, BOOST_PP_CAT(inherit,n_))
196 #if n_ == BOOST_MPL_LIMIT_METAFUNCTION_ARITY
199 BOOST_MPL_PP_DEFAULT_PARAMS(n_, typename T, empty_base)
202 : BOOST_PP_CAT(inherit,n_)<BOOST_MPL_PP_PARAMS(n_, T)>
206 // 'na' specialization
208 struct inherit< BOOST_MPL_PP_ENUM(5, na) >
211 #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES)
212 BOOST_MPL_PP_DEFAULT_PARAMS(n_, typename T, empty_base)
214 BOOST_MPL_PP_PARAMS(n_, typename T)
218 : inherit< BOOST_MPL_PP_PARAMS(n_, T) >
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)
229 #endif // BOOST_PP_IS_ITERATING