|
Boost : |
Subject: Re: [boost] C++ function bind
From: Marcus Lindblom (macke_at_[hidden])
Date: 2009-04-18 05:16:32
claud.86_at_[hidden] 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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk