source: NonGTP/Boost/boost/mpl/inherit.hpp @ 857

Revision 857, 5.8 KB checked in by igarcia, 19 years ago (diff)
Line 
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// $Source: /cvsroot/boost/boost/boost/mpl/inherit.hpp,v $
18// $Date: 2004/09/02 15:40:41 $
19// $Revision: 1.5 $
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
48namespace 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
65template<
66      typename BOOST_MPL_AUX_NA_PARAM(T1)
67    , typename BOOST_MPL_AUX_NA_PARAM(T2)
68    >
69struct inherit2
70    : T1, T2
71{
72    typedef inherit2 type;
73    BOOST_MPL_AUX_LAMBDA_SUPPORT(2, inherit2, (T1,T2))
74};
75
76template< typename T1 >
77struct inherit2<T1,empty_base>
78{
79    typedef T1 type;
80    BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2, inherit2, (T1,empty_base))
81};
82
83template< typename T2 >
84struct 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
92template<>
93struct 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
101namespace aux {
102
103template< bool C1, bool C2 >
104struct inherit2_impl
105{
106    template< typename Derived, typename T1, typename T2 > struct result_
107        : T1, T2
108    {
109        typedef Derived type_;
110    };
111};
112
113template<>
114struct 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
123template<>
124struct 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
133template<>
134struct 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
144template<
145      typename BOOST_MPL_AUX_NA_PARAM(T1)
146    , typename BOOST_MPL_AUX_NA_PARAM(T2)
147    >
148struct 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
160BOOST_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
176template<
177      BOOST_MPL_PP_DEFAULT_PARAMS(n_, typename T, na)
178    >
179struct 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
194BOOST_MPL_AUX_NA_SPEC(n_, BOOST_PP_CAT(inherit,n_))
195
196#if n_ == BOOST_MPL_LIMIT_METAFUNCTION_ARITY
197/// primary template
198template<
199      BOOST_MPL_PP_DEFAULT_PARAMS(n_, typename T, empty_base)
200    >
201struct inherit
202    : BOOST_PP_CAT(inherit,n_)<BOOST_MPL_PP_PARAMS(n_, T)>
203{
204};
205
206// 'na' specialization
207template<>
208struct 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
223BOOST_MPL_AUX_NA_SPEC_LAMBDA(n_, inherit)
224BOOST_MPL_AUX_NA_SPEC_ARITY(n_, inherit)
225BOOST_MPL_AUX_NA_SPEC_TEMPLATE_ARITY(n_, n_, inherit)
226#endif
227
228#undef n_
229#endif // BOOST_PP_IS_ITERATING
Note: See TracBrowser for help on using the repository browser.