C++ function bind

Hi to all, i use libboost recently, it is the ideal solution for my software c++. Now I'm using asio and I need to invoke a function like this: fun(time_from_string("2010-01-30 5:03:02"),bind(&timer::run,this)); The body of fun will look like this: void fun(ptime t,void h) { ... timer.async_wait(h); ... } Obviously the return of the type of bind is not void and that is why there is an error. What kind should be the h parameter? Which is the prototype of fun? Thanks for your attention Claudio -- Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it: http://www.email.it/f Sponsor: Tutto in tempo reale sul tuo cellulare: news, messaggistica istantanea, email e molto altro ancora con m.email.Scopri di più Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=8919&d=20090417

claud.86@email.it wrote:
Hi to all, i use libboost recently, it is the ideal solution for my software c++. Now I'm using asio and I need to invoke a function like this:
fun(time_from_string("2010-01-30 5:03:02"),bind(&timer::run,this));
The body of fun will look like this:
void fun(ptime t,void h) { ... timer.async_wait(h); ... }
Obviously the return of the type of bind is not void and that is why there is an error. What kind should be the h parameter? Which is the prototype of fun?
It's a rather complex type, containig both a mem-funn-ptr and a timer pointer. I suggest you either make fun() a template function: template<class F> void fun(ptime t, F f) Or, change void to boost::function<void>, which is a good wrapper for eliminating complex types: void fun(ptime t, boost::function<void()> f) The latter has a very slight performance disadvantage but the former requires the full definition (i.e. source) of fun() to be visible. I'd go for the latter. Cheers, /Marcus

claud.86@email.it wrote:
Hi to all, i use libboost recently, it is the ideal solution for my software c++. Now I'm using asio and I need to invoke a function like this:
fun(time_from_string("2010-01-30 5:03:02"),bind(&timer::run,this));
The body of fun will look like this:
void fun(ptime t,void h) { ... timer.async_wait(h); ... }
Obviously the return of the type of bind is not void and that is why there is an error. What kind should be the h parameter? Which is the prototype of fun?
Usage questions about boost should go to the boost-help mailing list. You need to make fun a template over the function parameter. The return type can be derived using Boost's result_of protocol. I'm not 100% sure about the details, but it should be something like template <typename Fn> typename boost::result_of<Fn>::type run_at(ptime at, Fn fn); Sebastian
participants (3)
-
claud.86@email.it
-
Marcus Lindblom
-
Sebastian Redl