]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/example/invert.cpp
1 /*==============================================================================
2 Copyright (c) 2005-2010 Joel de Guzman
3 Copyright (c) 2010 Thomas Heller
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
9 #include <boost/phoenix/phoenix.hpp>
10 #include <boost/proto/proto.hpp>
11 #include <boost/proto/debug.hpp>
13 namespace phoenix
= boost::phoenix
;
14 namespace proto
= boost::proto
;
18 template <typename Rule
>
24 using phoenix::evaluator
;
27 // redifining evaluator, this is because MSVC chokes on function types like:
29 #define evaluator(A0, A1) proto::call<phoenix::evaluator(A0, A1)>
33 struct invert_actions::when
<phoenix::rule::plus
>
35 phoenix::functional::make_minus(
36 evaluator(proto::_left
, phoenix::_context
)
37 , evaluator(proto::_right
, phoenix::_context
)
43 struct invert_actions::when
<phoenix::rule::minus
>
45 phoenix::functional::make_plus(
46 evaluator(proto::_left
, phoenix::_context
)
47 , evaluator(proto::_right
, phoenix::_context
)
53 struct invert_actions::when
<phoenix::rule::multiplies
>
55 phoenix::functional::make_divides(
56 evaluator(proto::_left
, phoenix::_context
)
57 , evaluator(proto::_right
, phoenix::_context
)
63 struct invert_actions::when
<phoenix::rule::divides
>
65 phoenix::functional::make_multiplies(
66 evaluator(proto::_left
, phoenix::_context
)
67 , evaluator(proto::_right
, phoenix::_context
)
76 template <typename Expr
>
77 void print_expr(Expr
const & expr
)
79 std::cout
<< "before inversion:\n";
80 proto::display_expr(expr
);
81 std::cout
<< "after inversion:\n";
94 template <typename Expr
>
96 boost::phoenix::result_of::eval
<
98 , phoenix::result_of::make_context
<
99 phoenix::result_of::make_env
<>::type
103 invert(Expr
const & expr
)
108 , phoenix::make_context(
117 using phoenix::placeholders::_1
;
118 using phoenix::placeholders::_2
;
119 using phoenix::placeholders::_3
;
120 using phoenix::placeholders::_4
;
124 print_expr(_1
+ _2
- _3
);
126 print_expr(_1
* _2
/ _3
);
127 print_expr(_1
* _2
+ _3
);
128 print_expr(_1
* _2
- _3
);
129 print_expr(if_(_1
* _4
)[_2
- _3
]);
131 print_expr(_1
* invert(_2
- _3
));