[Proto] Lazy function test
I am experimenting with the calculator example presented in the proto docs. I am unable to use pow<> when I define it using the make_expr (as preseneted in docs), but when I define it like proto::terminal< struct pow_fun<2> >::type const pow2 = {{}}; it works. I am using it like that in the main calculator_context ctx; ctx.args.push_back(2.0); std::cout << proto::eval( pow2(_1), ctx ) << std::endl; // ok with terminal std::cout << proto::eval( pow2(3.0), ctx ) << std::endl; // ok with terminal How can I make the make_expr version to work? Thanks in anticipation Noman Javed Orléans, France
You need to chaneg your gramamr so it match a pow_ tag and a terminal<pow_> -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35
joel falcou <joel.falcou <at> lri.fr> writes:
You need to chaneg your gramamr so it match a pow_ tag and a terminal<pow_>
Here is my function and the grammar struct INC_TAG { typedef double result_type; double operator()(double no) const { return 1.0+no; } }; template<typename Arg> typename proto::result_of::make_expr< proto::tag::function ,INC_TAG ,Arg
::type inc_(Arg const &arg) { return proto::make_expr<proto::tag::function>(INC_TAG(), arg); }
struct calculator_grammar : proto::or_< proto::plus< calculator_grammar, calculator_grammar > , proto::minus< calculator_grammar, calculator_grammar > , proto::multiplies< calculator_grammar, calculator_grammar > , proto::divides< calculator_grammar, calculator_grammar > , proto::function<proto::terminal<INC_TAG>, calculator_grammar > , proto::terminal< proto::_ > > {}; double d = inc_(_1)(2); // fine double d = inc_(2); // don't work Even though i have added the following in the grammar proto::function<proto::terminal<INC_TAG>, calculator_grammar >
participants (3)
-
joel falcou
-
Noman javed
-
Noman Javed