and_n.hpp 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
  2. #include <boost/proto/detail/preprocessed/and_n.hpp>
  3. #elif !defined(BOOST_PP_IS_ITERATING)
  4. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  5. #pragma wave option(preserve: 2, line: 0, output: "preprocessed/and_n.hpp")
  6. #endif
  7. ///////////////////////////////////////////////////////////////////////////////
  8. /// \file and_n.hpp
  9. /// Definitions of and_N, and_impl
  10. //
  11. // Copyright 2008 Eric Niebler. Distributed under the Boost
  12. // Software License, Version 1.0. (See accompanying file
  13. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  14. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  15. #pragma wave option(preserve: 1)
  16. #endif
  17. #define BOOST_PP_ITERATION_PARAMS_1 \
  18. (3, (2, BOOST_PP_MAX(BOOST_PROTO_MAX_ARITY, BOOST_PROTO_MAX_LOGICAL_ARITY), <boost/proto/detail/and_n.hpp>))
  19. #include BOOST_PP_ITERATE()
  20. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  21. #pragma wave option(output: null)
  22. #endif
  23. #else // BOOST_PP_IS_ITERATING
  24. #define N BOOST_PP_ITERATION()
  25. // Assymetry here between the handling of and_N and or_N because
  26. // and_N is used by lambda_matches up to BOOST_PROTO_MAX_ARITY,
  27. // regardless of how low BOOST_PROTO_MAX_LOGICAL_ARITY is.
  28. template<bool B, BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(N), typename P)>
  29. struct BOOST_PP_CAT(and_, N)
  30. #if 2 == N
  31. : mpl::bool_<P0::value>
  32. {};
  33. #else
  34. : BOOST_PP_CAT(and_, BOOST_PP_DEC(N))<
  35. P0::value BOOST_PP_COMMA_IF(BOOST_PP_SUB(N,2))
  36. BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_DEC(N), P)
  37. >
  38. {};
  39. #endif
  40. template<BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(N), typename P)>
  41. struct BOOST_PP_CAT(and_, N)<false, BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(N), P)>
  42. : mpl::false_
  43. {};
  44. #if N <= BOOST_PROTO_MAX_LOGICAL_ARITY
  45. template<BOOST_PP_ENUM_PARAMS(N, typename G), typename Expr, typename State, typename Data>
  46. struct _and_impl<proto::and_<BOOST_PP_ENUM_PARAMS(N, G)>, Expr, State, Data>
  47. : proto::transform_impl<Expr, State, Data>
  48. {
  49. #define M0(Z, N, DATA) \
  50. typedef \
  51. typename proto::when<proto::_, BOOST_PP_CAT(G, N)> \
  52. ::template impl<Expr, State, Data> \
  53. BOOST_PP_CAT(Gimpl, N); \
  54. /**/
  55. BOOST_PP_REPEAT(N, M0, ~)
  56. #undef M0
  57. typedef typename BOOST_PP_CAT(Gimpl, BOOST_PP_DEC(N))::result_type result_type;
  58. result_type operator()(
  59. typename _and_impl::expr_param e
  60. , typename _and_impl::state_param s
  61. , typename _and_impl::data_param d
  62. ) const
  63. {
  64. // Fix: jfalcou - 12/29/2010
  65. // Avoid the use of comma operator here so as not to find Proto's
  66. // by accident.
  67. // expands to G0()(e,s,d); G1()(e,s,d); ... G{N-1}()(e,s,d);
  68. #define M0(Z,N,DATA) BOOST_PP_CAT(Gimpl,N)()(e,s,d);
  69. BOOST_PP_REPEAT(BOOST_PP_DEC(N),M0,~)
  70. return BOOST_PP_CAT(Gimpl,BOOST_PP_DEC(N))()(e,s,d);
  71. #undef M0
  72. }
  73. };
  74. #endif
  75. #undef N
  76. #endif