Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2007 Joel de Guzman
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 ==============================================================================*/
|
Chris@16
|
7 #ifndef PHOENIX_OPERATOR_ARITHMETIC_HPP
|
Chris@16
|
8 #define PHOENIX_OPERATOR_ARITHMETIC_HPP
|
Chris@16
|
9
|
Chris@16
|
10 #include <boost/spirit/home/phoenix/core/composite.hpp>
|
Chris@16
|
11 #include <boost/spirit/home/phoenix/core/compose.hpp>
|
Chris@16
|
12 #include <boost/spirit/home/phoenix/detail/type_deduction.hpp>
|
Chris@16
|
13 #include <boost/spirit/home/phoenix/operator/detail/unary_eval.hpp>
|
Chris@16
|
14 #include <boost/spirit/home/phoenix/operator/detail/unary_compose.hpp>
|
Chris@16
|
15 #include <boost/spirit/home/phoenix/operator/detail/binary_eval.hpp>
|
Chris@16
|
16 #include <boost/spirit/home/phoenix/operator/detail/binary_compose.hpp>
|
Chris@16
|
17
|
Chris@16
|
18 namespace boost { namespace phoenix
|
Chris@16
|
19 {
|
Chris@16
|
20 struct negate_eval;
|
Chris@16
|
21 struct posit_eval;
|
Chris@16
|
22 struct pre_increment_eval;
|
Chris@16
|
23 struct pre_decrement_eval;
|
Chris@16
|
24 struct post_increment_eval;
|
Chris@16
|
25 struct post_decrement_eval;
|
Chris@16
|
26
|
Chris@16
|
27 struct plus_assign_eval;
|
Chris@16
|
28 struct minus_assign_eval;
|
Chris@16
|
29 struct multiplies_assign_eval;
|
Chris@16
|
30 struct divides_assign_eval;
|
Chris@16
|
31 struct modulus_assign_eval;
|
Chris@16
|
32
|
Chris@16
|
33 struct plus_eval;
|
Chris@16
|
34 struct minus_eval;
|
Chris@16
|
35 struct multiplies_eval;
|
Chris@16
|
36 struct divides_eval;
|
Chris@16
|
37 struct modulus_eval;
|
Chris@16
|
38
|
Chris@16
|
39 BOOST_UNARY_RESULT_OF(-x, result_of_negate)
|
Chris@16
|
40 BOOST_UNARY_RESULT_OF(+x, result_of_posit)
|
Chris@16
|
41 BOOST_UNARY_RESULT_OF(++x, result_of_pre_increment)
|
Chris@16
|
42 BOOST_UNARY_RESULT_OF(--x, result_of_pre_decrement)
|
Chris@16
|
43 BOOST_UNARY_RESULT_OF(x++, result_of_post_increment)
|
Chris@16
|
44 BOOST_UNARY_RESULT_OF(x--, result_of_post_decrement)
|
Chris@16
|
45
|
Chris@16
|
46 BOOST_BINARY_RESULT_OF(x += y, result_of_plus_assign)
|
Chris@16
|
47 BOOST_BINARY_RESULT_OF(x -= y, result_of_minus_assign)
|
Chris@16
|
48 BOOST_BINARY_RESULT_OF(x *= y, result_of_multiplies_assign)
|
Chris@16
|
49 BOOST_BINARY_RESULT_OF(x /= y, result_of_divides_assign)
|
Chris@16
|
50 BOOST_BINARY_RESULT_OF(x %= y, result_of_modulus_assign)
|
Chris@16
|
51
|
Chris@16
|
52 BOOST_BINARY_RESULT_OF(x + y, result_of_plus)
|
Chris@16
|
53 BOOST_BINARY_RESULT_OF(x - y, result_of_minus)
|
Chris@16
|
54 BOOST_BINARY_RESULT_OF(x * y, result_of_multiplies)
|
Chris@16
|
55 BOOST_BINARY_RESULT_OF(x / y, result_of_divides)
|
Chris@16
|
56 BOOST_BINARY_RESULT_OF(x % y, result_of_modulus)
|
Chris@16
|
57
|
Chris@16
|
58 #define x a0.eval(env)
|
Chris@16
|
59 #define y a1.eval(env)
|
Chris@16
|
60
|
Chris@16
|
61 PHOENIX_UNARY_EVAL(negate_eval, result_of_negate, -x)
|
Chris@16
|
62 PHOENIX_UNARY_EVAL(posit_eval, result_of_posit, +x)
|
Chris@16
|
63 PHOENIX_UNARY_EVAL(pre_increment_eval, result_of_pre_increment, ++x)
|
Chris@16
|
64 PHOENIX_UNARY_EVAL(pre_decrement_eval, result_of_pre_decrement, --x)
|
Chris@16
|
65 PHOENIX_UNARY_EVAL(post_increment_eval, result_of_post_increment, x++)
|
Chris@16
|
66 PHOENIX_UNARY_EVAL(post_decrement_eval, result_of_post_decrement, x--)
|
Chris@16
|
67
|
Chris@16
|
68 PHOENIX_BINARY_EVAL(plus_assign_eval, result_of_plus_assign, x += y)
|
Chris@16
|
69 PHOENIX_BINARY_EVAL(minus_assign_eval, result_of_minus_assign, x -= y)
|
Chris@16
|
70 PHOENIX_BINARY_EVAL(multiplies_assign_eval, result_of_multiplies_assign, x *= y)
|
Chris@16
|
71 PHOENIX_BINARY_EVAL(divides_assign_eval, result_of_divides_assign, x /= y)
|
Chris@16
|
72 PHOENIX_BINARY_EVAL(modulus_assign_eval, result_of_modulus_assign, x %= y)
|
Chris@16
|
73
|
Chris@16
|
74 PHOENIX_BINARY_EVAL(plus_eval, result_of_plus, x + y)
|
Chris@16
|
75 PHOENIX_BINARY_EVAL(minus_eval, result_of_minus, x - y)
|
Chris@16
|
76 PHOENIX_BINARY_EVAL(multiplies_eval, result_of_multiplies, x * y)
|
Chris@16
|
77 PHOENIX_BINARY_EVAL(divides_eval, result_of_divides, x / y)
|
Chris@16
|
78 PHOENIX_BINARY_EVAL(modulus_eval, result_of_modulus, x % y)
|
Chris@16
|
79
|
Chris@16
|
80 PHOENIX_UNARY_COMPOSE(negate_eval, -)
|
Chris@16
|
81 PHOENIX_UNARY_COMPOSE(posit_eval, +)
|
Chris@16
|
82 PHOENIX_UNARY_COMPOSE(pre_increment_eval, ++)
|
Chris@16
|
83 PHOENIX_UNARY_COMPOSE(pre_decrement_eval, --)
|
Chris@16
|
84
|
Chris@16
|
85 template <typename T0>
|
Chris@16
|
86 inline actor<typename as_composite<post_increment_eval, actor<T0> >::type>
|
Chris@16
|
87 operator++(actor<T0> const& a0, int) // special case
|
Chris@16
|
88 {
|
Chris@16
|
89 return compose<post_increment_eval>(a0);
|
Chris@16
|
90 }
|
Chris@16
|
91
|
Chris@16
|
92 template <typename T0>
|
Chris@16
|
93 inline actor<typename as_composite<post_decrement_eval, actor<T0> >::type>
|
Chris@16
|
94 operator--(actor<T0> const& a0, int) // special case
|
Chris@16
|
95 {
|
Chris@16
|
96 return compose<post_decrement_eval>(a0);
|
Chris@16
|
97 }
|
Chris@16
|
98
|
Chris@16
|
99 PHOENIX_BINARY_COMPOSE(plus_assign_eval, +=)
|
Chris@16
|
100 PHOENIX_BINARY_COMPOSE(minus_assign_eval, -=)
|
Chris@16
|
101 PHOENIX_BINARY_COMPOSE(multiplies_assign_eval, *=)
|
Chris@16
|
102 PHOENIX_BINARY_COMPOSE(divides_assign_eval, /=)
|
Chris@16
|
103 PHOENIX_BINARY_COMPOSE(modulus_assign_eval, %=)
|
Chris@16
|
104
|
Chris@16
|
105 PHOENIX_BINARY_COMPOSE(plus_eval, +)
|
Chris@16
|
106 PHOENIX_BINARY_COMPOSE(minus_eval, -)
|
Chris@16
|
107 PHOENIX_BINARY_COMPOSE(multiplies_eval, *)
|
Chris@16
|
108 PHOENIX_BINARY_COMPOSE(divides_eval, /)
|
Chris@16
|
109 PHOENIX_BINARY_COMPOSE(modulus_eval, %)
|
Chris@16
|
110
|
Chris@16
|
111 #undef x
|
Chris@16
|
112 #undef y
|
Chris@16
|
113 }}
|
Chris@16
|
114
|
Chris@16
|
115 #endif
|