full_lambda.hpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. #if !defined(BOOST_PP_IS_ITERATING)
  2. ///// header body
  3. #ifndef BOOST_MPL_AUX_FULL_LAMBDA_HPP_INCLUDED
  4. #define BOOST_MPL_AUX_FULL_LAMBDA_HPP_INCLUDED
  5. // Copyright Aleksey Gurtovoy 2001-2004
  6. //
  7. // Distributed under the Boost Software License, Version 1.0.
  8. // (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // See http://www.boost.org/libs/mpl for documentation.
  12. // $Id$
  13. // $Date$
  14. // $Revision$
  15. #if !defined(BOOST_MPL_PREPROCESSING_MODE)
  16. # include <boost/mpl/lambda_fwd.hpp>
  17. # include <boost/mpl/bind_fwd.hpp>
  18. # include <boost/mpl/protect.hpp>
  19. # include <boost/mpl/quote.hpp>
  20. # include <boost/mpl/arg.hpp>
  21. # include <boost/mpl/bool.hpp>
  22. # include <boost/mpl/int_fwd.hpp>
  23. # include <boost/mpl/aux_/template_arity.hpp>
  24. # include <boost/mpl/aux_/na_spec.hpp>
  25. # include <boost/mpl/aux_/config/ttp.hpp>
  26. # if defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
  27. # include <boost/mpl/if.hpp>
  28. # endif
  29. #endif
  30. #include <boost/mpl/aux_/lambda_arity_param.hpp>
  31. #include <boost/mpl/aux_/config/use_preprocessed.hpp>
  32. #if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
  33. && !defined(BOOST_MPL_PREPROCESSING_MODE)
  34. # define BOOST_MPL_PREPROCESSED_HEADER full_lambda.hpp
  35. # include <boost/mpl/aux_/include_preprocessed.hpp>
  36. #else
  37. # include <boost/mpl/limits/arity.hpp>
  38. # include <boost/mpl/aux_/preprocessor/default_params.hpp>
  39. # include <boost/mpl/aux_/preprocessor/params.hpp>
  40. # include <boost/mpl/aux_/preprocessor/enum.hpp>
  41. # include <boost/mpl/aux_/preprocessor/repeat.hpp>
  42. # include <boost/mpl/aux_/config/dmc_ambiguous_ctps.hpp>
  43. # include <boost/preprocessor/iterate.hpp>
  44. # include <boost/preprocessor/comma_if.hpp>
  45. # include <boost/preprocessor/inc.hpp>
  46. # include <boost/preprocessor/cat.hpp>
  47. namespace boost { namespace mpl {
  48. // local macros, #undef-ined at the end of the header
  49. # define AUX778076_LAMBDA_PARAMS(i_, param) \
  50. BOOST_MPL_PP_PARAMS(i_, param) \
  51. /**/
  52. # define AUX778076_BIND_PARAMS(param) \
  53. BOOST_MPL_PP_PARAMS( \
  54. BOOST_MPL_LIMIT_METAFUNCTION_ARITY \
  55. , param \
  56. ) \
  57. /**/
  58. # define AUX778076_BIND_N_PARAMS(i_, param) \
  59. BOOST_PP_COMMA_IF(i_) \
  60. BOOST_MPL_PP_PARAMS(i_, param) \
  61. /**/
  62. # define AUX778076_ARITY_PARAM(param) \
  63. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(param) \
  64. /**/
  65. #define n_ BOOST_MPL_LIMIT_METAFUNCTION_ARITY
  66. namespace aux {
  67. template<
  68. BOOST_MPL_PP_DEFAULT_PARAMS(n_,bool C,false)
  69. >
  70. struct lambda_or
  71. : true_
  72. {
  73. };
  74. template<>
  75. struct lambda_or< BOOST_MPL_PP_ENUM(n_,false) >
  76. : false_
  77. {
  78. };
  79. } // namespace aux
  80. #undef n_
  81. template<
  82. typename T
  83. , typename Tag
  84. AUX778076_ARITY_PARAM(typename Arity)
  85. >
  86. struct lambda
  87. {
  88. typedef false_ is_le;
  89. typedef T result_;
  90. typedef T type;
  91. };
  92. template<
  93. typename T
  94. >
  95. struct is_lambda_expression
  96. : lambda<T>::is_le
  97. {
  98. };
  99. template< int N, typename Tag >
  100. struct lambda< arg<N>,Tag AUX778076_ARITY_PARAM(int_<-1>) >
  101. {
  102. typedef true_ is_le;
  103. typedef mpl::arg<N> result_; // qualified for the sake of MIPSpro 7.41
  104. typedef mpl::protect<result_> type;
  105. };
  106. #define BOOST_PP_ITERATION_PARAMS_1 \
  107. (3,(0, BOOST_MPL_LIMIT_METAFUNCTION_ARITY, <boost/mpl/aux_/full_lambda.hpp>))
  108. #include BOOST_PP_ITERATE()
  109. /// special case for 'protect'
  110. template< typename T, typename Tag >
  111. struct lambda< mpl::protect<T>,Tag AUX778076_ARITY_PARAM(int_<1>) >
  112. {
  113. typedef false_ is_le;
  114. typedef mpl::protect<T> result_;
  115. typedef result_ type;
  116. };
  117. /// specializations for the main 'bind' form
  118. template<
  119. typename F, AUX778076_BIND_PARAMS(typename T)
  120. , typename Tag
  121. >
  122. struct lambda<
  123. bind<F,AUX778076_BIND_PARAMS(T)>
  124. , Tag
  125. AUX778076_ARITY_PARAM(int_<BOOST_PP_INC(BOOST_MPL_LIMIT_METAFUNCTION_ARITY)>)
  126. >
  127. {
  128. typedef false_ is_le;
  129. typedef bind<F, AUX778076_BIND_PARAMS(T)> result_;
  130. typedef result_ type;
  131. };
  132. #if defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
  133. template<
  134. typename F
  135. , typename Tag1
  136. , typename Tag2
  137. , typename Arity
  138. >
  139. struct lambda<
  140. lambda<F,Tag1,Arity>
  141. , Tag2
  142. , int_<3>
  143. >
  144. {
  145. typedef lambda< F,Tag2 > l1;
  146. typedef lambda< Tag1,Tag2 > l2;
  147. typedef typename l1::is_le is_le;
  148. typedef bind1< quote1<aux::template_arity>, typename l1::result_ > arity_;
  149. typedef lambda< typename if_<is_le,arity_,Arity>::type,Tag2 > l3;
  150. typedef aux::le_result3<is_le, Tag2, mpl::lambda, l1, l2, l3> le_result_;
  151. typedef typename le_result_::result_ result_;
  152. typedef typename le_result_::type type;
  153. };
  154. #elif !defined(BOOST_MPL_CFG_DMC_AMBIGUOUS_CTPS)
  155. /// workaround for MWCW 8.3+/EDG < 303, leads to ambiguity on Digital Mars
  156. template<
  157. typename F, typename Tag1, typename Tag2
  158. >
  159. struct lambda<
  160. lambda< F,Tag1 >
  161. , Tag2
  162. >
  163. {
  164. typedef lambda< F,Tag2 > l1;
  165. typedef lambda< Tag1,Tag2 > l2;
  166. typedef typename l1::is_le is_le;
  167. typedef aux::le_result2<is_le, Tag2, mpl::lambda, l1, l2> le_result_;
  168. typedef typename le_result_::result_ result_;
  169. typedef typename le_result_::type type;
  170. };
  171. #endif
  172. # undef AUX778076_ARITY_PARAM
  173. # undef AUX778076_BIND_N_PARAMS
  174. # undef AUX778076_BIND_PARAMS
  175. # undef AUX778076_LAMBDA_PARAMS
  176. #if !defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
  177. BOOST_MPL_AUX_NA_SPEC(2, lambda)
  178. #else
  179. BOOST_MPL_AUX_NA_SPEC2(2, 3, lambda)
  180. #endif
  181. }}
  182. #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
  183. #endif // BOOST_MPL_AUX_FULL_LAMBDA_HPP_INCLUDED
  184. ///// iteration, depth == 1
  185. // For gcc 4.4 compatability, we must include the
  186. // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
  187. #else // BOOST_PP_IS_ITERATING
  188. #if BOOST_PP_ITERATION_DEPTH() == 1
  189. #define i_ BOOST_PP_FRAME_ITERATION(1)
  190. #if i_ > 0
  191. namespace aux {
  192. # define AUX778076_RESULT(unused, i_, T) \
  193. BOOST_PP_COMMA_IF(i_) \
  194. typename BOOST_PP_CAT(T, BOOST_PP_INC(i_))::result_ \
  195. /**/
  196. # define AUX778076_TYPE(unused, i_, T) \
  197. BOOST_PP_COMMA_IF(i_) \
  198. typename BOOST_PP_CAT(T, BOOST_PP_INC(i_))::type \
  199. /**/
  200. template<
  201. typename IsLE, typename Tag
  202. , template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
  203. , AUX778076_LAMBDA_PARAMS(i_, typename L)
  204. >
  205. struct BOOST_PP_CAT(le_result,i_)
  206. {
  207. typedef F<
  208. BOOST_MPL_PP_REPEAT(i_, AUX778076_TYPE, L)
  209. > result_;
  210. typedef result_ type;
  211. };
  212. template<
  213. typename Tag
  214. , template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
  215. , AUX778076_LAMBDA_PARAMS(i_, typename L)
  216. >
  217. struct BOOST_PP_CAT(le_result,i_)< true_,Tag,F,AUX778076_LAMBDA_PARAMS(i_, L) >
  218. {
  219. typedef BOOST_PP_CAT(bind,i_)<
  220. BOOST_PP_CAT(quote,i_)<F,Tag>
  221. , BOOST_MPL_PP_REPEAT(i_, AUX778076_RESULT, L)
  222. > result_;
  223. typedef mpl::protect<result_> type;
  224. };
  225. # undef AUX778076_TYPE
  226. # undef AUX778076_RESULT
  227. } // namespace aux
  228. # define AUX778076_LAMBDA_TYPEDEF(unused, i_, T) \
  229. typedef lambda< BOOST_PP_CAT(T, BOOST_PP_INC(i_)), Tag > \
  230. BOOST_PP_CAT(l,BOOST_PP_INC(i_)); \
  231. /**/
  232. # define AUX778076_IS_LE_TYPEDEF(unused, i_, unused2) \
  233. typedef typename BOOST_PP_CAT(l,BOOST_PP_INC(i_))::is_le \
  234. BOOST_PP_CAT(is_le,BOOST_PP_INC(i_)); \
  235. /**/
  236. # define AUX778076_IS_LAMBDA_EXPR(unused, i_, unused2) \
  237. BOOST_PP_COMMA_IF(i_) \
  238. BOOST_PP_CAT(is_le,BOOST_PP_INC(i_))::value \
  239. /**/
  240. template<
  241. template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
  242. , AUX778076_LAMBDA_PARAMS(i_, typename T)
  243. , typename Tag
  244. >
  245. struct lambda<
  246. F<AUX778076_LAMBDA_PARAMS(i_, T)>
  247. , Tag
  248. AUX778076_ARITY_PARAM(int_<i_>)
  249. >
  250. {
  251. BOOST_MPL_PP_REPEAT(i_, AUX778076_LAMBDA_TYPEDEF, T)
  252. BOOST_MPL_PP_REPEAT(i_, AUX778076_IS_LE_TYPEDEF, unused)
  253. typedef typename aux::lambda_or<
  254. BOOST_MPL_PP_REPEAT(i_, AUX778076_IS_LAMBDA_EXPR, unused)
  255. >::type is_le;
  256. typedef aux::BOOST_PP_CAT(le_result,i_)<
  257. is_le, Tag, F, AUX778076_LAMBDA_PARAMS(i_, l)
  258. > le_result_;
  259. typedef typename le_result_::result_ result_;
  260. typedef typename le_result_::type type;
  261. };
  262. # undef AUX778076_IS_LAMBDA_EXPR
  263. # undef AUX778076_IS_LE_TYPEDEF
  264. # undef AUX778076_LAMBDA_TYPEDEF
  265. #endif // i_ > 0
  266. template<
  267. typename F AUX778076_BIND_N_PARAMS(i_, typename T)
  268. , typename Tag
  269. >
  270. struct lambda<
  271. BOOST_PP_CAT(bind,i_)<F AUX778076_BIND_N_PARAMS(i_, T)>
  272. , Tag
  273. AUX778076_ARITY_PARAM(int_<BOOST_PP_INC(i_)>)
  274. >
  275. {
  276. typedef false_ is_le;
  277. typedef BOOST_PP_CAT(bind,i_)<
  278. F
  279. AUX778076_BIND_N_PARAMS(i_, T)
  280. > result_;
  281. typedef result_ type;
  282. };
  283. #undef i_
  284. #endif // BOOST_PP_ITERATION_DEPTH()
  285. #endif // BOOST_PP_IS_ITERATING