Skip to content

Instantly share code, notes, and snippets.

@sithhell
Created December 28, 2013 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sithhell/8159502 to your computer and use it in GitHub Desktop.
Save sithhell/8159502 to your computer and use it in GitHub Desktop.
#include <boost/phoenix.hpp>
int main()
{
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
using boost::phoenix::arg_names::arg3;
using boost::phoenix::local_names::_a;
using boost::phoenix::local_names::_b;
using boost::phoenix::lambda;
using boost::phoenix::bind;
// how should i define myplus, mymult and myinit, so that
// expr1 is arg1 + myplus_f<double>(3.0)(1,arg2) + mymult_f<double>(3.0)(2,arg3)
auto myplus = lambda(_a = arg1, _b = arg2)[arg1 + _a + _b];
auto mymult = lambda(_a = arg1, _b = arg2)[arg1 * _a * _b];
auto myinit = bind(arg1, arg2);
auto expr0 = lambda[arg1] + myplus(1,arg2) + mymult(2,arg3);
auto expr1 = myinit( expr0, 3.0 );
// evaluate expr1 with actual arguments
double r = expr1(1,2,3);
// modify the internally held values of myplus_f<double>(3.0) and mymult_f<double>(3.0)
// so that expr1 becomes equivalent to arg1 + myplus_f<double>(5.0)(1,arg2) + mymult_f<double>(5.0)(2,arg3)
auto expr2 = myinit( expr0, 5.0 );
//myreset(expr1, 5.0);
// evaluate with new value members of myplus_f and mymult_f
double r2 = expr2(1,2,3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment