blob: 0a3284d98c0e820f162438fa310a81ace0138220 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001
Jeff Thompson3d613fd2013-10-15 15:39:04 -07002#if !defined(NDNBOOST_PP_IS_ITERATING)
Jeff Thompsona28eed82013-08-22 16:21:10 -07003
4///// header body
5
Jeff Thompson3d613fd2013-10-15 15:39:04 -07006#ifndef NDNBOOST_MPL_AUX_FULL_LAMBDA_HPP_INCLUDED
7#define NDNBOOST_MPL_AUX_FULL_LAMBDA_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -07008
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: full_lambda.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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070021#if !defined(NDNBOOST_MPL_PREPROCESSING_MODE)
Jeff Thompsona28eed82013-08-22 16:21:10 -070022# include <ndnboost/mpl/lambda_fwd.hpp>
23# include <ndnboost/mpl/bind_fwd.hpp>
24# include <ndnboost/mpl/protect.hpp>
25# include <ndnboost/mpl/quote.hpp>
26# include <ndnboost/mpl/arg.hpp>
27# include <ndnboost/mpl/bool.hpp>
28# include <ndnboost/mpl/int_fwd.hpp>
29# include <ndnboost/mpl/aux_/template_arity.hpp>
30# include <ndnboost/mpl/aux_/na_spec.hpp>
31# include <ndnboost/mpl/aux_/config/ttp.hpp>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070032# if defined(NDNBOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
Jeff Thompsona28eed82013-08-22 16:21:10 -070033# include <ndnboost/mpl/if.hpp>
34# endif
35#endif
36
37#include <ndnboost/mpl/aux_/lambda_arity_param.hpp>
38#include <ndnboost/mpl/aux_/config/use_preprocessed.hpp>
39
Jeff Thompson3d613fd2013-10-15 15:39:04 -070040#if !defined(NDNBOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
41 && !defined(NDNBOOST_MPL_PREPROCESSING_MODE)
Jeff Thompsona28eed82013-08-22 16:21:10 -070042
Jeff Thompson3d613fd2013-10-15 15:39:04 -070043# define NDNBOOST_MPL_PREPROCESSED_HEADER full_lambda.hpp
Jeff Thompsona28eed82013-08-22 16:21:10 -070044# include <ndnboost/mpl/aux_/include_preprocessed.hpp>
45
46#else
47
48# include <ndnboost/mpl/limits/arity.hpp>
49# include <ndnboost/mpl/aux_/preprocessor/default_params.hpp>
50# include <ndnboost/mpl/aux_/preprocessor/params.hpp>
51# include <ndnboost/mpl/aux_/preprocessor/enum.hpp>
52# include <ndnboost/mpl/aux_/preprocessor/repeat.hpp>
53# include <ndnboost/mpl/aux_/config/dmc_ambiguous_ctps.hpp>
54
55# include <ndnboost/preprocessor/iterate.hpp>
56# include <ndnboost/preprocessor/comma_if.hpp>
57# include <ndnboost/preprocessor/inc.hpp>
58# include <ndnboost/preprocessor/cat.hpp>
59
60namespace ndnboost { namespace mpl {
61
62// local macros, #undef-ined at the end of the header
63# define AUX778076_LAMBDA_PARAMS(i_, param) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070064 NDNBOOST_MPL_PP_PARAMS(i_, param) \
Jeff Thompsona28eed82013-08-22 16:21:10 -070065 /**/
66
67# define AUX778076_BIND_PARAMS(param) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070068 NDNBOOST_MPL_PP_PARAMS( \
69 NDNBOOST_MPL_LIMIT_METAFUNCTION_ARITY \
Jeff Thompsona28eed82013-08-22 16:21:10 -070070 , param \
71 ) \
72 /**/
73
74# define AUX778076_BIND_N_PARAMS(i_, param) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070075 NDNBOOST_PP_COMMA_IF(i_) \
76 NDNBOOST_MPL_PP_PARAMS(i_, param) \
Jeff Thompsona28eed82013-08-22 16:21:10 -070077 /**/
78
79# define AUX778076_ARITY_PARAM(param) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070080 NDNBOOST_MPL_AUX_LAMBDA_ARITY_PARAM(param) \
Jeff Thompsona28eed82013-08-22 16:21:10 -070081 /**/
82
83
Jeff Thompson3d613fd2013-10-15 15:39:04 -070084#define n_ NDNBOOST_MPL_LIMIT_METAFUNCTION_ARITY
Jeff Thompsona28eed82013-08-22 16:21:10 -070085namespace aux {
86
87template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070088 NDNBOOST_MPL_PP_DEFAULT_PARAMS(n_,bool C,false)
Jeff Thompsona28eed82013-08-22 16:21:10 -070089 >
90struct lambda_or
91 : true_
92{
93};
94
95template<>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070096struct lambda_or< NDNBOOST_MPL_PP_ENUM(n_,false) >
Jeff Thompsona28eed82013-08-22 16:21:10 -070097 : 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700134#define NDNBOOST_PP_ITERATION_PARAMS_1 \
135 (3,(0, NDNBOOST_MPL_LIMIT_METAFUNCTION_ARITY, <ndnboost/mpl/aux_/full_lambda.hpp>))
136#include NDNBOOST_PP_ITERATE()
Jeff Thompsona28eed82013-08-22 16:21:10 -0700137
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700155 AUX778076_ARITY_PARAM(int_<NDNBOOST_PP_INC(NDNBOOST_MPL_LIMIT_METAFUNCTION_ARITY)>)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700156 >
157{
158 typedef false_ is_le;
159 typedef bind<F, AUX778076_BIND_PARAMS(T)> result_;
160 typedef result_ type;
161};
162
163
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700164#if defined(NDNBOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700165
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700190#elif !defined(NDNBOOST_MPL_CFG_DMC_AMBIGUOUS_CTPS)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700191
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700217#if !defined(NDNBOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
218NDNBOOST_MPL_AUX_NA_SPEC(2, lambda)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700219#else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700220NDNBOOST_MPL_AUX_NA_SPEC2(2, 3, lambda)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700221#endif
222
223}}
224
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700225#endif // NDNBOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
226#endif // NDNBOOST_MPL_AUX_FULL_LAMBDA_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -0700227
228///// iteration, depth == 1
229
230// For gcc 4.4 compatability, we must include the
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700231// NDNBOOST_PP_ITERATION_DEPTH test inside an #else clause.
232#else // NDNBOOST_PP_IS_ITERATING
233#if NDNBOOST_PP_ITERATION_DEPTH() == 1
234#define i_ NDNBOOST_PP_FRAME_ITERATION(1)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700235
236#if i_ > 0
237
238namespace aux {
239
240# define AUX778076_RESULT(unused, i_, T) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700241 NDNBOOST_PP_COMMA_IF(i_) \
242 typename NDNBOOST_PP_CAT(T, NDNBOOST_PP_INC(i_))::result_ \
Jeff Thompsona28eed82013-08-22 16:21:10 -0700243 /**/
244
245# define AUX778076_TYPE(unused, i_, T) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700246 NDNBOOST_PP_COMMA_IF(i_) \
247 typename NDNBOOST_PP_CAT(T, NDNBOOST_PP_INC(i_))::type \
Jeff Thompsona28eed82013-08-22 16:21:10 -0700248 /**/
249
250template<
251 typename IsLE, typename Tag
252 , template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
253 , AUX778076_LAMBDA_PARAMS(i_, typename L)
254 >
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700255struct NDNBOOST_PP_CAT(le_result,i_)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700256{
257 typedef F<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700258 NDNBOOST_MPL_PP_REPEAT(i_, AUX778076_TYPE, L)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700259 > result_;
260
261 typedef result_ type;
262};
263
264template<
265 typename Tag
266 , template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
267 , AUX778076_LAMBDA_PARAMS(i_, typename L)
268 >
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700269struct NDNBOOST_PP_CAT(le_result,i_)< true_,Tag,F,AUX778076_LAMBDA_PARAMS(i_, L) >
Jeff Thompsona28eed82013-08-22 16:21:10 -0700270{
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700271 typedef NDNBOOST_PP_CAT(bind,i_)<
272 NDNBOOST_PP_CAT(quote,i_)<F,Tag>
273 , NDNBOOST_MPL_PP_REPEAT(i_, AUX778076_RESULT, L)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700274 > result_;
275
276 typedef mpl::protect<result_> type;
277};
278
279# undef AUX778076_TYPE
280# undef AUX778076_RESULT
281
282} // namespace aux
283
284
285# define AUX778076_LAMBDA_TYPEDEF(unused, i_, T) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700286 typedef lambda< NDNBOOST_PP_CAT(T, NDNBOOST_PP_INC(i_)), Tag > \
287 NDNBOOST_PP_CAT(l,NDNBOOST_PP_INC(i_)); \
Jeff Thompsona28eed82013-08-22 16:21:10 -0700288/**/
289
290# define AUX778076_IS_LE_TYPEDEF(unused, i_, unused2) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700291 typedef typename NDNBOOST_PP_CAT(l,NDNBOOST_PP_INC(i_))::is_le \
292 NDNBOOST_PP_CAT(is_le,NDNBOOST_PP_INC(i_)); \
Jeff Thompsona28eed82013-08-22 16:21:10 -0700293/**/
294
295# define AUX778076_IS_LAMBDA_EXPR(unused, i_, unused2) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700296 NDNBOOST_PP_COMMA_IF(i_) \
297 NDNBOOST_PP_CAT(is_le,NDNBOOST_PP_INC(i_))::value \
Jeff Thompsona28eed82013-08-22 16:21:10 -0700298/**/
299
300template<
301 template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
302 , AUX778076_LAMBDA_PARAMS(i_, typename T)
303 , typename Tag
304 >
305struct lambda<
306 F<AUX778076_LAMBDA_PARAMS(i_, T)>
307 , Tag
308 AUX778076_ARITY_PARAM(int_<i_>)
309 >
310{
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700311 NDNBOOST_MPL_PP_REPEAT(i_, AUX778076_LAMBDA_TYPEDEF, T)
312 NDNBOOST_MPL_PP_REPEAT(i_, AUX778076_IS_LE_TYPEDEF, unused)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700313
314 typedef typename aux::lambda_or<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700315 NDNBOOST_MPL_PP_REPEAT(i_, AUX778076_IS_LAMBDA_EXPR, unused)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700316 >::type is_le;
317
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700318 typedef aux::NDNBOOST_PP_CAT(le_result,i_)<
Jeff Thompsona28eed82013-08-22 16:21:10 -0700319 is_le, Tag, F, AUX778076_LAMBDA_PARAMS(i_, l)
320 > le_result_;
321
322 typedef typename le_result_::result_ result_;
323 typedef typename le_result_::type type;
324};
325
326
327# undef AUX778076_IS_LAMBDA_EXPR
328# undef AUX778076_IS_LE_TYPEDEF
329# undef AUX778076_LAMBDA_TYPEDEF
330
331#endif // i_ > 0
332
333template<
334 typename F AUX778076_BIND_N_PARAMS(i_, typename T)
335 , typename Tag
336 >
337struct lambda<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700338 NDNBOOST_PP_CAT(bind,i_)<F AUX778076_BIND_N_PARAMS(i_, T)>
Jeff Thompsona28eed82013-08-22 16:21:10 -0700339 , Tag
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700340 AUX778076_ARITY_PARAM(int_<NDNBOOST_PP_INC(i_)>)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700341 >
342{
343 typedef false_ is_le;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700344 typedef NDNBOOST_PP_CAT(bind,i_)<
Jeff Thompsona28eed82013-08-22 16:21:10 -0700345 F
346 AUX778076_BIND_N_PARAMS(i_, T)
347 > result_;
348
349 typedef result_ type;
350};
351
352#undef i_
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700353#endif // NDNBOOST_PP_ITERATION_DEPTH()
354#endif // NDNBOOST_PP_IS_ITERATING