I am trying to create a transform where I replace occurrences of
proto::terminal<term> with proto::terminal >. I
want N to increment for every proto::terminal<term> encountered. So
far I have the following code :
#include
#include
#include
#include <iostream>
using namespace std;
namespace proto=boost::proto;
namespace mpl=boost::mpl;
struct term {};
template<typename>
struct newterm {};
proto::terminal<term>::type const a = {{}};
proto::terminal<term>::type const b = {{}};
proto::terminal<term>::type const c = {{}};
struct xform_callable
: proto::callable {
template<typename>
struct result;
template
struct result {
typedef typename proto::result_of::make_expr::type type;
};
template
struct result {
typedef typename proto::result_of::make_expr::type type;
};
template<typename N>
typename proto::result_of::make_expr::type
operator()(const term &, N) {
return proto::make_exprproto::tag::terminal(newterm<N>());
}
template
typename proto::result_of::make_expr::type
operator()(tag, LHS l, RHS r) const {
return proto::make_expr<tag>(l, r);
}
};
struct xform
: proto::or_<
proto::when<
proto::terminal<term>,
xform_callable(proto::_value, mpl::nextproto::_state())>,
proto::when<
proto::plus,
xform_callable(proto::tag_ofproto::_expr(),
xform(proto::_left, proto::_state), xform(proto::_right,
proto::_state))>
{};
int main()
{
mpl::plus, mpl::int_<1> >();
proto::display_expr(xform()(a+b/c, mpl::int_<0>()));
return 0;
}
I pass in mpl::int_<0>() as the initial state and call mpl::next when
I match proto::terminal<term>. As the output would indicate, this is
not working. Every time I think I understand proto transforms,
something basic like this stumps me. I will be grateful for any hints
on how to accomplish this.
Thanks,
Manjunath