Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost.bind] How to retrieve the function type of a boost::bind result
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-01-26 12:40:44


AMDG

Olaf Krzikalla wrote:
> The following snippet won't compile since the compiler can't deduce
> the template argument:
>
> template<typename T>
> void foo(boost::function<T> func) { /*...*/ }
>
> void bar() {}
>
> void baz()
> {
> foo(boost::bind(&bar)); // error
> foo<void()>(boost::bind(&bar)); // OK
> foo(boost::function<void()>(boost::bind(&bar))); // OK
> }
>
> 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.

Consider:

struct F {
    typedef void result_type;
    template<class T>
    void operator()(const T&) const;
};

boost::bind(F(), _1);

In Christ,
Steven Watanabe


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