how to avoid static member function when using gsl with c++

You can easily wrap member functions using the following code (which is a well known solution) class gsl_function_pp : public gsl_function { public: gsl_function_pp(std::function<double(double)> const& func) : _func(func){ function=&gsl_function_pp::invoke; params=this; } private: std::function<double(double)> _func; static double invoke(double x, void *params) { return static_cast<gsl_function_pp*>(params)->_func(x); } }; Then you can use std::bind to wrap the member function … Read more

C function pointers with C++11 lambdas

Using a void* is typical of C callback interfaces to pass some “state” to the function. However, std::function does not need this because std::function supports “stateful functions”. So, you could do something like this: double Integrate( std::function<double(double)> func, double a, double b) { typedef std::function<double(double)> fun_type; ::: F.function = [](double x, void* p){ return (*static_cast<fun_type*>(p))(x); … Read more