forked from headmyshoulder/odeint-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
n_ary_helper.hpp
80 lines (65 loc) · 3.04 KB
/
n_ary_helper.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
[auto_generated]
boost/numeric/odeint/external/openmp/n_ary_helper.hpp
Macros to generate scale_sumN and for_eachN functors.
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_OPENMP_N_ARY_HELPER_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_OPENMP_N_ARY_HELPER_HPP_INCLUDED
#include <boost/preprocessor/repetition.hpp>
// generate "param0 = first, param1 = param0, param2 = param1"
#define BOOST_ENUM_PARAMS_WITH_PREV(count, param, first) \
BOOST_PP_ENUM(count, BOOST_ENUM_PARAMS_WITH_PREV_, (param, first))
#define BOOST_ENUM_PARAMS_WITH_PREV_(z, n, data) \
BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n) = \
BOOST_PP_IF(n, \
BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), BOOST_PP_DEC(n)), \
BOOST_PP_TUPLE_ELEM(2, 1, data))
// like BOOST_PP_ENUM_BINARY_PARAMS(n, p1, p2) but with statements.
// "p1 ## 0 p2 ## 0 ; p1 ## 1 p2 ## 1 ; ..."
#define BOOST_ENUM_BINARY_STATEMENTS(count, p1, p2) \
BOOST_PP_REPEAT(count, BOOST_ENUM_BINARY_STATEMENTS_, (p1, p2))
#define BOOST_ENUM_BINARY_STATEMENTS_(z, n, data) \
BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n) \
BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, data), n) ;
// like BOOST_PP_ENUM_BINARY_PARAMS(n, p1, p2) but p2 is in parens.
// "p1 ## 0 (p2 ## 0) , p1 ## 1 (p2 ## 1) , ..."
#define BOOST_ENUM_UNARY_CALLS(count, p1, p2) \
BOOST_PP_ENUM(count, BOOST_ENUM_UNARY_CALLS_, (p1, p2))
#define BOOST_ENUM_UNARY_CALLS_(z, n, data) \
BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n) \
( BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n) )
// maximum arity for scale_sum and for_each
#define BOOST_ODEINT_N_ARY_MAX 15
// generate scale_sum1 to scale_sumN, operator body generated by macro(N)
#define BOOST_ODEINT_GEN_SCALE_SUM(macro) \
BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_INC(BOOST_ODEINT_N_ARY_MAX), \
BOOST_ODEINT_GEN_SCALE_SUM_, macro)
#define BOOST_ODEINT_GEN_SCALE_SUM_(z, n, macro) \
template< BOOST_ENUM_PARAMS_WITH_PREV(n, class Fac, double) > \
struct scale_sum##n \
{ \
BOOST_ENUM_BINARY_STATEMENTS(n, const Fac, m_alpha) \
\
scale_sum##n( BOOST_PP_ENUM_BINARY_PARAMS(n, Fac, alpha) ) \
: BOOST_ENUM_UNARY_CALLS(n, m_alpha, alpha) {} \
\
template< BOOST_PP_ENUM_PARAMS(n, class T) > \
void operator()( T0 &t0 , \
BOOST_PP_ENUM_SHIFTED_BINARY_PARAMS(n, const T, &t) ) const \
{ macro(n) } \
typedef void result_type; \
};
// generate for_each1 to for_eachN, body generated by macro(N)
#define BOOST_ODEINT_GEN_FOR_EACH(macro) \
BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_INC(BOOST_ODEINT_N_ARY_MAX), \
BOOST_ODEINT_GEN_FOR_EACH_, macro)
#define BOOST_ODEINT_GEN_FOR_EACH_(z, n, macro) \
template< BOOST_PP_ENUM_PARAMS(n, class S) , class Op > \
static void for_each##n ( BOOST_PP_ENUM_BINARY_PARAMS(n, S, &s) , Op op ) \
{ macro(n) }
#endif