Chris@102: /* Chris@102: [auto_generated] Chris@102: boost/numeric/odeint/util/n_ary_helper.hpp Chris@102: Chris@102: Macros to generate scale_sumN and for_eachN functors. Chris@102: Chris@102: Copyright 2013 Karsten Ahnert Chris@102: Copyright 2013 Mario Mulansky Chris@102: Copyright 2013 Pascal Germroth Chris@102: Chris@102: Distributed under the Boost Software License, Version 1.0. Chris@102: (See accompanying file LICENSE_1_0.txt or Chris@102: copy at http://www.boost.org/LICENSE_1_0.txt) Chris@102: */ Chris@102: Chris@102: #ifndef BOOST_NUMERIC_ODEINT_UTIL_N_ARY_HELPER_HPP_INCLUDED Chris@102: #define BOOST_NUMERIC_ODEINT_UTIL_N_ARY_HELPER_HPP_INCLUDED Chris@102: Chris@102: #include Chris@102: Chris@102: // like BOOST_PP_ENUM_SHIFTED but with a comma in front like _TRAILING Chris@102: #define BOOST_ODEINT_ENUM_TRAILING_SHIFTED_PARAMS(count, param) \ Chris@102: BOOST_PP_COMMA_IF(BOOST_PP_DEC(count)) \ Chris@102: BOOST_PP_ENUM_SHIFTED_PARAMS(count, param) Chris@102: Chris@102: #define BOOST_ODEINT_ENUM_TRAILING_SHIFTED_BINARY_PARAMS(count, p1, p2) \ Chris@102: BOOST_PP_COMMA_IF(BOOST_PP_DEC(count)) \ Chris@102: BOOST_PP_ENUM_SHIFTED_BINARY_PARAMS(count, p1, p2) Chris@102: Chris@102: // like BOOST_PP_ENUM_SHIFTED_BINARY_PARAMS(n, p1, p2) but p2 is shifted left. Chris@102: // generate "p1 ## 0 = p2, p1 ## 1 = p3 ## 0, p1 ## 2 = p3 ## 1" Chris@102: #define BOOST_ODEINT_ENUM_LSHIFTED_BINARY_PARAMS(count, p1, p2, p3) \ Chris@102: BOOST_PP_ENUM(count, BOOST_ODEINT_ENUM_LSHIFTED_BINARY_PARAMS_, (p1, p2, p3)) Chris@102: #define BOOST_ODEINT_ENUM_LSHIFTED_BINARY_PARAMS_(z, n, data) \ Chris@102: BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 0, data), n) \ Chris@102: BOOST_PP_IF(n, \ Chris@102: BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 2, data), BOOST_PP_DEC(n)), \ Chris@102: BOOST_PP_TUPLE_ELEM(3, 1, data)) Chris@102: Chris@102: // like BOOST_PP_ENUM_BINARY_PARAMS(n, p1, p2) but with statements. Chris@102: // "p1 ## 0 p2 ## 0 ; p1 ## 1 p2 ## 1 ; ..." Chris@102: #define BOOST_ODEINT_ENUM_BINARY_STATEMENTS(count, p1, p2) \ Chris@102: BOOST_PP_REPEAT(count, BOOST_ODEINT_ENUM_BINARY_STATEMENTS_, (p1, p2)) Chris@102: #define BOOST_ODEINT_ENUM_BINARY_STATEMENTS_(z, n, data) \ Chris@102: BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n) \ Chris@102: BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, data), n) ; Chris@102: Chris@102: // like BOOST_PP_ENUM_BINARY_PARAMS(n, p1, p2) but p2 is in parens. Chris@102: // "p1 ## 0 (p2 ## 0) , p1 ## 1 (p2 ## 1) , ..." Chris@102: #define BOOST_ODEINT_ENUM_UNARY_CALLS(count, p1, p2) \ Chris@102: BOOST_PP_ENUM(count, BOOST_ODEINT_ENUM_UNARY_CALLS_, (p1, p2)) Chris@102: #define BOOST_ODEINT_ENUM_SHIFTED_UNARY_CALLS(count, p1, p2) \ Chris@102: BOOST_PP_ENUM_SHIFTED(count, BOOST_ODEINT_ENUM_UNARY_CALLS_, (p1, p2)) Chris@102: #define BOOST_ODEINT_ENUM_TRAILING_SHIFTED_UNARY_CALLS(count, p1, p2) \ Chris@102: BOOST_PP_COMMA_IF(BOOST_PP_DEC(count)) \ Chris@102: BOOST_PP_ENUM_SHIFTED(count, BOOST_ODEINT_ENUM_UNARY_CALLS_, (p1, p2)) Chris@102: #define BOOST_ODEINT_ENUM_UNARY_CALLS_(z, n, data) \ Chris@102: BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n) \ Chris@102: ( BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, data), n) ) Chris@102: Chris@102: Chris@102: // maximum arity + 1 for scale_sum and for_each Chris@102: #define BOOST_ODEINT_N_ARY_MAX 16 Chris@102: Chris@102: Chris@102: // generate scale_sum1 to scale_sumN, operator body generated by macro(N) Chris@102: #define BOOST_ODEINT_GEN_SCALE_SUM(macro) \ Chris@102: BOOST_PP_REPEAT_FROM_TO(1, BOOST_ODEINT_N_ARY_MAX, BOOST_ODEINT_GEN_SCALE_SUM_, macro) Chris@102: #define BOOST_ODEINT_GEN_SCALE_SUM_(z, n, macro) \ Chris@102: template< BOOST_ODEINT_ENUM_LSHIFTED_BINARY_PARAMS(n, class Fac, = double, = Fac) > \ Chris@102: struct BOOST_PP_CAT(scale_sum, n) \ Chris@102: { \ Chris@102: BOOST_ODEINT_ENUM_BINARY_STATEMENTS(n, const Fac, m_alpha) \ Chris@102: \ Chris@102: BOOST_PP_CAT(scale_sum, n) \ Chris@102: ( BOOST_PP_ENUM_BINARY_PARAMS(n, Fac, alpha) ) \ Chris@102: : BOOST_ODEINT_ENUM_UNARY_CALLS(n, m_alpha, alpha) {} \ Chris@102: \ Chris@102: template< BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), class T) > \ Chris@102: void operator()( T0 &t0 \ Chris@102: BOOST_ODEINT_ENUM_TRAILING_SHIFTED_BINARY_PARAMS(BOOST_PP_INC(n), const T, &t) \ Chris@102: ) const \ Chris@102: { macro(n) } \ Chris@102: typedef void result_type; \ Chris@102: }; Chris@102: Chris@102: // generate for_each1 to for_eachN, body generated by macro(N) Chris@102: #define BOOST_ODEINT_GEN_FOR_EACH(macro) \ Chris@102: BOOST_PP_REPEAT_FROM_TO(1, BOOST_ODEINT_N_ARY_MAX, BOOST_ODEINT_GEN_FOR_EACH_, macro) Chris@102: #define BOOST_ODEINT_GEN_FOR_EACH_(z, n, macro) \ Chris@102: template< BOOST_PP_ENUM_PARAMS(n, class S) , class Op > \ Chris@102: static void for_each##n ( BOOST_PP_ENUM_BINARY_PARAMS(n, S, &s) , Op op ) \ Chris@102: { macro(n) } Chris@102: Chris@102: Chris@102: #endif