n_ary_helper.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/util/n_ary_helper.hpp
  4. Macros to generate scale_sumN and for_eachN functors.
  5. Copyright 2013 Karsten Ahnert
  6. Copyright 2013 Mario Mulansky
  7. Copyright 2013 Pascal Germroth
  8. Distributed under the Boost Software License, Version 1.0.
  9. (See accompanying file LICENSE_1_0.txt or
  10. copy at http://www.boost.org/LICENSE_1_0.txt)
  11. */
  12. #ifndef BOOST_NUMERIC_ODEINT_UTIL_N_ARY_HELPER_HPP_INCLUDED
  13. #define BOOST_NUMERIC_ODEINT_UTIL_N_ARY_HELPER_HPP_INCLUDED
  14. #include <boost/preprocessor/repetition.hpp>
  15. // like BOOST_PP_ENUM_SHIFTED but with a comma in front like _TRAILING
  16. #define BOOST_ODEINT_ENUM_TRAILING_SHIFTED_PARAMS(count, param) \
  17. BOOST_PP_COMMA_IF(BOOST_PP_DEC(count)) \
  18. BOOST_PP_ENUM_SHIFTED_PARAMS(count, param)
  19. #define BOOST_ODEINT_ENUM_TRAILING_SHIFTED_BINARY_PARAMS(count, p1, p2) \
  20. BOOST_PP_COMMA_IF(BOOST_PP_DEC(count)) \
  21. BOOST_PP_ENUM_SHIFTED_BINARY_PARAMS(count, p1, p2)
  22. // like BOOST_PP_ENUM_SHIFTED_BINARY_PARAMS(n, p1, p2) but p2 is shifted left.
  23. // generate "p1 ## 0 = p2, p1 ## 1 = p3 ## 0, p1 ## 2 = p3 ## 1"
  24. #define BOOST_ODEINT_ENUM_LSHIFTED_BINARY_PARAMS(count, p1, p2, p3) \
  25. BOOST_PP_ENUM(count, BOOST_ODEINT_ENUM_LSHIFTED_BINARY_PARAMS_, (p1, p2, p3))
  26. #define BOOST_ODEINT_ENUM_LSHIFTED_BINARY_PARAMS_(z, n, data) \
  27. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 0, data), n) \
  28. BOOST_PP_IF(n, \
  29. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 2, data), BOOST_PP_DEC(n)), \
  30. BOOST_PP_TUPLE_ELEM(3, 1, data))
  31. // like BOOST_PP_ENUM_BINARY_PARAMS(n, p1, p2) but with statements.
  32. // "p1 ## 0 p2 ## 0 ; p1 ## 1 p2 ## 1 ; ..."
  33. #define BOOST_ODEINT_ENUM_BINARY_STATEMENTS(count, p1, p2) \
  34. BOOST_PP_REPEAT(count, BOOST_ODEINT_ENUM_BINARY_STATEMENTS_, (p1, p2))
  35. #define BOOST_ODEINT_ENUM_BINARY_STATEMENTS_(z, n, data) \
  36. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n) \
  37. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, data), n) ;
  38. // like BOOST_PP_ENUM_BINARY_PARAMS(n, p1, p2) but p2 is in parens.
  39. // "p1 ## 0 (p2 ## 0) , p1 ## 1 (p2 ## 1) , ..."
  40. #define BOOST_ODEINT_ENUM_UNARY_CALLS(count, p1, p2) \
  41. BOOST_PP_ENUM(count, BOOST_ODEINT_ENUM_UNARY_CALLS_, (p1, p2))
  42. #define BOOST_ODEINT_ENUM_SHIFTED_UNARY_CALLS(count, p1, p2) \
  43. BOOST_PP_ENUM_SHIFTED(count, BOOST_ODEINT_ENUM_UNARY_CALLS_, (p1, p2))
  44. #define BOOST_ODEINT_ENUM_TRAILING_SHIFTED_UNARY_CALLS(count, p1, p2) \
  45. BOOST_PP_COMMA_IF(BOOST_PP_DEC(count)) \
  46. BOOST_PP_ENUM_SHIFTED(count, BOOST_ODEINT_ENUM_UNARY_CALLS_, (p1, p2))
  47. #define BOOST_ODEINT_ENUM_UNARY_CALLS_(z, n, data) \
  48. BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n) \
  49. ( BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, data), n) )
  50. // maximum arity + 1 for scale_sum and for_each
  51. #define BOOST_ODEINT_N_ARY_MAX 16
  52. // generate scale_sum1 to scale_sumN, operator body generated by macro(N)
  53. #define BOOST_ODEINT_GEN_SCALE_SUM(macro) \
  54. BOOST_PP_REPEAT_FROM_TO(1, BOOST_ODEINT_N_ARY_MAX, BOOST_ODEINT_GEN_SCALE_SUM_, macro)
  55. #define BOOST_ODEINT_GEN_SCALE_SUM_(z, n, macro) \
  56. template< BOOST_ODEINT_ENUM_LSHIFTED_BINARY_PARAMS(n, class Fac, = double, = Fac) > \
  57. struct BOOST_PP_CAT(scale_sum, n) \
  58. { \
  59. BOOST_ODEINT_ENUM_BINARY_STATEMENTS(n, const Fac, m_alpha) \
  60. \
  61. BOOST_PP_CAT(scale_sum, n) \
  62. ( BOOST_PP_ENUM_BINARY_PARAMS(n, Fac, alpha) ) \
  63. : BOOST_ODEINT_ENUM_UNARY_CALLS(n, m_alpha, alpha) {} \
  64. \
  65. template< BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), class T) > \
  66. void operator()( T0 &t0 \
  67. BOOST_ODEINT_ENUM_TRAILING_SHIFTED_BINARY_PARAMS(BOOST_PP_INC(n), const T, &t) \
  68. ) const \
  69. { macro(n) } \
  70. typedef void result_type; \
  71. };
  72. // generate for_each1 to for_eachN, body generated by macro(N)
  73. #define BOOST_ODEINT_GEN_FOR_EACH(macro) \
  74. BOOST_PP_REPEAT_FROM_TO(1, BOOST_ODEINT_N_ARY_MAX, BOOST_ODEINT_GEN_FOR_EACH_, macro)
  75. #define BOOST_ODEINT_GEN_FOR_EACH_(z, n, macro) \
  76. template< BOOST_PP_ENUM_PARAMS(n, class S) , class Op > \
  77. static void for_each##n ( BOOST_PP_ENUM_BINARY_PARAMS(n, S, &s) , Op op ) \
  78. { macro(n) }
  79. #endif