Skip to content

Instantly share code, notes, and snippets.

@diazona
Created November 23, 2014 11:07
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 diazona/c03e80227f39cbdc4937 to your computer and use it in GitHub Desktop.
Save diazona/c03e80227f39cbdc4937 to your computer and use it in GitHub Desktop.
#include <muParser.h>
#include <iostream>
#include <functional>
#include <boost/bind.hpp>
struct MyClass {
double m_arbitrary_value;
MyClass(int arbitrary_value) : m_arbitrary_value(arbitrary_value) {}
double make_a_value(double a, double b) {return m_arbitrary_value*a+b;}
};
double wrapper(double a, double b, MyClass* p) {
return p->make_a_value(a, b);
}
int main(const int argc, const char** argv) {
// 1. just call the function
// this works fine
MyClass instance(5);
std::cout << wrapper(3, 2, &instance) << std::endl;
// 2. bind the function and call the resulting functor
// this works fine
std::cout << boost::bind(&wrapper, _1, _2, &instance)(3, 2) << std::endl;
// 3. pass the function to Parser::DefineFun
// this fails
mu::Parser p;
p.DefineFun("f", boost::bind(&wrapper, _1, _2, &instance));
p.SetExpr("f(3, 2)");
std::cout << p.Eval() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment