What is the purpose of std::function and how to use it?

std::function is a type erasure object. That means it erases the details of how some operations happen, and provides a uniform run time interface to them. For std::function, the primary1 operations are copy/move, destruction, and ‘invocation’ with operator() — the ‘function like call operator’. In less abstruse English, it means that std::function can contain almost … Read more

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

How to directly bind a member function to an std::function in Visual Studio 11?

I think according to the C++11 standard, this should be supported Not really, because a non-static member function has an implicit first parameter of type (cv-qualified) YourType*, so in this case it does not match void(int). Hence the need for std::bind: Register(std::bind(&Class::Function, PointerToSomeInstanceOfClass, _1)); For example Class c; using namespace std::placeholders; // for _1, _2 … Read more