How can I also include function bodies in the conversion of a Boost Phoenix expression?
For example, I created the Lazy Functions Boost Phoenix Starter Kit section and created a lazy add function:
struct my_lazy_add_impl {
typedef int result_type;
template <typename T>
T operator()(T x, T y) const { return x+y; }
};
phoenix::function<my_lazy_add_impl> my_add;
Then I prepare a simple plus-minus transformation from the previous question shown here:
struct invrt:
proto::or_<
proto::when<
proto::plus<proto::_, proto::_>,
proto::functional::make_expr<proto::tag::minus>(
invrt(proto::_left), invrt(proto::_right)
)
>,
proto::otherwise<
proto::nary_expr<proto::_, proto::vararg<invrt> >
>
>
{};
However, when I apply the inverted Phoenix expression lambda, using my_add, to its arguments, as shown below, it seems that the alleged inversion has not been achieved. Is there a recommended way to make function calls in Phoenix that can facilitate such conversions?
int main(int argc, char *argv[])
{
auto f = phoenix::lambda(_a = 0)[my_add(_1,_2)];
auto g = invrt()(phoenix::lambda(_a = 0)[my_add(_1,_2)]);
std::cout << f()(1,2) << std::endl;
std::cout << g()(1,2) << std::endl;
return 0;
}
source
share