callback and boost:function

Guys, First thank you for a wonderful library and all the hours of work that is put into boost to make it what it is today. Is there anyway in C++ to setup a callback to a member function that takes two arguments I am trying to use boost::function but that only works with std::bind1st that does only take one parameter. I want to wrap some existing C code with C++. The function I want to call back is declareed like this: struct X { double foo(double x , void * p); }; Idealy I would like to use lambda to remove the void* and replace it with _1, _2 etc. But I am not sure how that works with callbacks. I had a look at the libsigc++ that seems to be able to handle callbacks with more arguments but the lambda stuff does not work under Visual Studio 2003 at least. Regards Lars Schouw --------------------------------- Yahoo! Photos Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

<snip>
I want to wrap some existing C code with C++. The function I want to call back is declareed like this: struct X { double foo(double x , void * p); };
Idealy I would like to use lambda to remove the void* and replace it with _1, _2 etc. But I am not sure how > that works with callbacks.
Use boost::bind or boost::lambda::bind. For example: // An instance of x X x; // A binary function boost::function<double (double, void*)> fBinary; // A unary function boost::function<double (void*)> fUnary; // A nullary function boost::function<double (void)> fNullary; // Bind x.foo to binary function fBinary = boost::bind(&X::foo, boost::ref(x), _1, _2); // Bind x.foo to unary function "hardcoding" second parameter fUnary = boost::bind(&X::foo, boost::ref(x), 5.25, _1); // Bind x.foo to nullary function "hardcoding" first and second parameter int i = 5; fNullary = boost::bind(&X::foo, boost::ref(x), 5.25, &i); // Execute binary function passing both arguments fBinary(5.25, &i); // Execute unary function passing 1 argument fUnary(&i); // Execute nullary function fNullary(); Hope this helps, -delfin
participants (2)
-
Delfin Rojas
-
Lars Schouw