Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost.bind] How to retrieve the function type of a boost::bind result
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-01-27 10:30:58


Olaf Krzikalla:
...
>>> template<typename T>
>>> void foo(boost::function<T> func) { /*...*/ }
>>>
>>> void bar() {}
>>>
>>> void baz()
>>> {
>>> foo(boost::bind(&bar)); // error
>>> }
>>>
>>> So how do I get the first line of baz to work? That is, is there a
>>> generic way to compute the boost::function type from the bind result?
>>
>> There is not because the boost::function type is not unique.
> Hmm, indeed.
> However wouldn't it be possible for the bind (member) function pointer
> overloads to return a "_bind_t_ex" type derived from _bind_t containing a
> function_type typedef? In my particular use case I will use bind with
> function pointers only.

In general you can't deduce a boost::function<> from the result of bind,
even if you only use functions.

function<void()> f1 = bind( bar ); // OK
function<void(string)> f2 = bind( bar ); // OK
function<void(int,int)> f3 = bind( bar ); // still OK

In fact, this ability to ignore arguments is the primary reason to use
bind(bar), if you didn't need it, you could have used just bar.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net