source: NonGTP/Boost/boost/mpl/aux_/full_lambda.hpp @ 857

Revision 857, 8.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_AUX_FULL_LAMBDA_HPP_INCLUDED
7#define BOOST_MPL_AUX_FULL_LAMBDA_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/aux_/full_lambda.hpp,v $
18// $Date: 2004/09/04 01:10:19 $
19// $Revision: 1.14 $
20
21#if !defined(BOOST_MPL_PREPROCESSING_MODE)
22#   include <boost/mpl/lambda_fwd.hpp>
23#   include <boost/mpl/bind_fwd.hpp>
24#   include <boost/mpl/protect.hpp>
25#   include <boost/mpl/quote.hpp>
26#   include <boost/mpl/arg.hpp>
27#   include <boost/mpl/bool.hpp>
28#   include <boost/mpl/int_fwd.hpp>
29#   include <boost/mpl/aux_/template_arity.hpp>
30#   include <boost/mpl/aux_/na_spec.hpp>
31#   include <boost/mpl/aux_/config/ttp.hpp>
32#   if defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
33#       include <boost/mpl/if.hpp>
34#   endif
35#endif
36
37#include <boost/mpl/aux_/lambda_arity_param.hpp>
38#include <boost/mpl/aux_/config/use_preprocessed.hpp>
39
40#if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
41    && !defined(BOOST_MPL_PREPROCESSING_MODE)
42
43#   define BOOST_MPL_PREPROCESSED_HEADER full_lambda.hpp
44#   include <boost/mpl/aux_/include_preprocessed.hpp>
45
46#else
47
48#   include <boost/mpl/limits/arity.hpp>
49#   include <boost/mpl/aux_/preprocessor/default_params.hpp>
50#   include <boost/mpl/aux_/preprocessor/params.hpp>
51#   include <boost/mpl/aux_/preprocessor/enum.hpp>
52#   include <boost/mpl/aux_/preprocessor/repeat.hpp>
53#   include <boost/mpl/aux_/config/dmc_ambiguous_ctps.hpp>
54
55#   include <boost/preprocessor/iterate.hpp>
56#   include <boost/preprocessor/comma_if.hpp>
57#   include <boost/preprocessor/inc.hpp>
58#   include <boost/preprocessor/cat.hpp>
59
60namespace boost { namespace mpl {
61
62// local macros, #undef-ined at the end of the header
63#   define AUX778076_LAMBDA_PARAMS(i_, param) \
64    BOOST_MPL_PP_PARAMS(i_, param) \
65    /**/
66
67#   define AUX778076_BIND_PARAMS(param) \
68    BOOST_MPL_PP_PARAMS( \
69          BOOST_MPL_LIMIT_METAFUNCTION_ARITY \
70        , param \
71        ) \
72    /**/
73
74#   define AUX778076_BIND_N_PARAMS(i_, param) \
75    BOOST_PP_COMMA_IF(i_) \
76    BOOST_MPL_PP_PARAMS(i_, param) \
77    /**/
78
79#   define AUX778076_ARITY_PARAM(param) \
80    BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(param) \
81    /**/
82
83
84#define n_ BOOST_MPL_LIMIT_METAFUNCTION_ARITY
85namespace aux {
86
87template<
88      BOOST_MPL_PP_DEFAULT_PARAMS(n_,bool C,false)
89    >
90struct lambda_or
91    : true_
92{
93};
94
95template<>
96struct lambda_or< BOOST_MPL_PP_ENUM(n_,false) >
97    : false_
98{
99};
100
101} // namespace aux
102#undef n_
103
104template<
105      typename T
106    , typename Tag
107    AUX778076_ARITY_PARAM(typename Arity)
108    >
109struct lambda
110{
111    typedef false_ is_le;
112    typedef T result_;
113    typedef T type;
114};
115
116template<
117      typename T
118    >
119struct is_lambda_expression
120    : lambda<T>::is_le
121{
122};
123
124
125template< int N, typename Tag >
126struct lambda< arg<N>,Tag AUX778076_ARITY_PARAM(int_<-1>) >
127{
128    typedef true_ is_le;
129    typedef mpl::arg<N> result_; // qualified for the sake of MIPSpro 7.41
130    typedef mpl::protect<result_> type;
131};
132
133
134#define BOOST_PP_ITERATION_PARAMS_1 \
135    (3,(0, BOOST_MPL_LIMIT_METAFUNCTION_ARITY, <boost/mpl/aux_/full_lambda.hpp>))
136#include BOOST_PP_ITERATE()
137
138/// special case for 'protect'
139template< typename T, typename Tag >
140struct lambda< mpl::protect<T>,Tag AUX778076_ARITY_PARAM(int_<1>) >
141{
142    typedef false_ is_le;
143    typedef mpl::protect<T> result_;
144    typedef result_ type;
145};
146
147/// specializations for the main 'bind' form
148template<
149      typename F, AUX778076_BIND_PARAMS(typename T)
150    , typename Tag
151    >
152struct lambda<
153          bind<F,AUX778076_BIND_PARAMS(T)>
154        , Tag
155        AUX778076_ARITY_PARAM(int_<BOOST_PP_INC(BOOST_MPL_LIMIT_METAFUNCTION_ARITY)>)
156        >
157{
158    typedef false_ is_le;
159    typedef bind<F, AUX778076_BIND_PARAMS(T)> result_;
160    typedef result_ type;
161};
162
163
164#if defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
165
166template<
167      typename F
168    , typename Tag1
169    , typename Tag2
170    , typename Arity
171    >
172struct lambda<
173          lambda<F,Tag1,Arity>
174        , Tag2
175        , int_<3>
176        >
177{
178    typedef lambda< F,Tag2 > l1;
179    typedef lambda< Tag1,Tag2 > l2;
180
181    typedef typename l1::is_le is_le;
182    typedef bind1< quote1<aux::template_arity>, typename l1::result_ > arity_;
183    typedef lambda< typename if_<is_le,arity_,Arity>::type,Tag2 > l3;
184   
185    typedef aux::le_result3<is_le, Tag2, mpl::lambda, l1, l2, l3> le_result_;
186    typedef typename le_result_::result_ result_;
187    typedef typename le_result_::type type;
188};
189
190#elif !defined(BOOST_MPL_CFG_DMC_AMBIGUOUS_CTPS)
191
192/// workaround for MWCW 8.3+/EDG < 303, leads to ambiguity on Digital Mars
193template<
194      typename F, typename Tag1, typename Tag2
195    >
196struct lambda<
197          lambda< F,Tag1 >
198        , Tag2
199        >
200{
201    typedef lambda< F,Tag2 > l1;
202    typedef lambda< Tag1,Tag2 > l2;
203   
204    typedef typename l1::is_le is_le;
205    typedef aux::le_result2<is_le, Tag2, mpl::lambda, l1, l2> le_result_;
206    typedef typename le_result_::result_ result_;
207    typedef typename le_result_::type type;
208};
209
210#endif
211
212#   undef AUX778076_ARITY_PARAM
213#   undef AUX778076_BIND_N_PARAMS
214#   undef AUX778076_BIND_PARAMS
215#   undef AUX778076_LAMBDA_PARAMS
216
217#if !defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
218BOOST_MPL_AUX_NA_SPEC(2, lambda)
219#else
220BOOST_MPL_AUX_NA_SPEC2(2, 3, lambda)
221#endif
222
223}}
224
225#endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
226#endif // BOOST_MPL_AUX_FULL_LAMBDA_HPP_INCLUDED
227
228///// iteration, depth == 1
229
230#elif BOOST_PP_ITERATION_DEPTH() == 1
231#define i_ BOOST_PP_FRAME_ITERATION(1)
232
233#if i_ > 0
234
235namespace aux {
236
237#   define AUX778076_RESULT(unused, i_, T) \
238    BOOST_PP_COMMA_IF(i_) \
239    typename BOOST_PP_CAT(T, BOOST_PP_INC(i_))::result_ \
240    /**/
241
242#   define AUX778076_TYPE(unused, i_, T) \
243    BOOST_PP_COMMA_IF(i_) \
244    typename BOOST_PP_CAT(T, BOOST_PP_INC(i_))::type \
245    /**/
246
247template<
248      typename IsLE, typename Tag
249    , template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
250    , AUX778076_LAMBDA_PARAMS(i_, typename L)
251    >
252struct BOOST_PP_CAT(le_result,i_)
253{
254    typedef F<
255          BOOST_MPL_PP_REPEAT(i_, AUX778076_TYPE, L)
256        > result_;
257   
258    typedef result_ type;
259};
260
261template<
262      typename Tag
263    , template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
264    , AUX778076_LAMBDA_PARAMS(i_, typename L)
265    >
266struct BOOST_PP_CAT(le_result,i_)< true_,Tag,F,AUX778076_LAMBDA_PARAMS(i_, L) >
267{
268    typedef BOOST_PP_CAT(bind,i_)<
269          BOOST_PP_CAT(quote,i_)<F,Tag>
270        , BOOST_MPL_PP_REPEAT(i_, AUX778076_RESULT, L)
271        > result_;
272
273    typedef mpl::protect<result_> type;
274};
275
276#   undef AUX778076_TYPE
277#   undef AUX778076_RESULT
278
279} // namespace aux
280
281
282#   define AUX778076_LAMBDA_TYPEDEF(unused, i_, T) \
283    typedef lambda< BOOST_PP_CAT(T, BOOST_PP_INC(i_)), Tag > \
284        BOOST_PP_CAT(l,BOOST_PP_INC(i_)); \
285/**/
286
287#   define AUX778076_IS_LE_TYPEDEF(unused, i_, unused2) \
288    typedef typename BOOST_PP_CAT(l,BOOST_PP_INC(i_))::is_le \
289        BOOST_PP_CAT(is_le,BOOST_PP_INC(i_)); \
290/**/
291
292#   define AUX778076_IS_LAMBDA_EXPR(unused, i_, unused2) \
293    BOOST_PP_COMMA_IF(i_) \
294    BOOST_PP_CAT(is_le,BOOST_PP_INC(i_))::value \
295/**/
296
297template<
298      template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
299    , AUX778076_LAMBDA_PARAMS(i_, typename T)
300    , typename Tag
301    >
302struct lambda<
303          F<AUX778076_LAMBDA_PARAMS(i_, T)>
304        , Tag
305        AUX778076_ARITY_PARAM(int_<i_>)
306        >
307{
308    BOOST_MPL_PP_REPEAT(i_, AUX778076_LAMBDA_TYPEDEF, T)
309    BOOST_MPL_PP_REPEAT(i_, AUX778076_IS_LE_TYPEDEF, unused)
310
311    typedef typename aux::lambda_or<
312          BOOST_MPL_PP_REPEAT(i_, AUX778076_IS_LAMBDA_EXPR, unused)
313        >::type is_le;
314
315    typedef aux::BOOST_PP_CAT(le_result,i_)<
316          is_le, Tag, F, AUX778076_LAMBDA_PARAMS(i_, l)
317        > le_result_;
318   
319    typedef typename le_result_::result_ result_;
320    typedef typename le_result_::type type;
321};
322
323
324#   undef AUX778076_IS_LAMBDA_EXPR
325#   undef AUX778076_IS_LE_TYPEDEF
326#   undef AUX778076_LAMBDA_TYPEDEF
327
328#endif // i_ > 0
329
330template<
331      typename F AUX778076_BIND_N_PARAMS(i_, typename T)
332    , typename Tag
333    >
334struct lambda<
335          BOOST_PP_CAT(bind,i_)<F AUX778076_BIND_N_PARAMS(i_, T)>
336        , Tag
337        AUX778076_ARITY_PARAM(int_<BOOST_PP_INC(i_)>)
338        >
339{
340    typedef false_ is_le;
341    typedef BOOST_PP_CAT(bind,i_)<
342          F
343        AUX778076_BIND_N_PARAMS(i_, T)
344        > result_;
345       
346    typedef result_ type;
347};
348
349#undef i_
350#endif // BOOST_PP_IS_ITERATING
Note: See TracBrowser for help on using the repository browser.