Boost logo

Boost :

Subject: Re: [boost] [function] support for overloaded function
From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-10-30 07:51:33


Oliver Kowalke:
> Hello,
> how can I support the return type of bind as well as function as function
> argument in following code.

...

> struct Y
> {
> template< typename R >
> void f( boost::function< R() > const& fn)
> {}
>
> template< typename R >
> void f( boost::function< R( X &) > const& fn)
> {}
> };

You can't; a nullary boost::bind expression can be converted to either
function<> and you can't tell with certainty which one the user has meant.

For the return type you can do:

struct Y
{
    template< typename R >
    void f1_( boost::function< R() > const& fn)
    { ... }

    template<class F>
    void f1( F f )
    {
        f1_( function<typename F::result_type>( f ) );
    }
};

but I see no reason to prefer the above over just doing:

struct Y
{
    template<class F>
    void f1( F f )
    { ... }
};

--
Peter Dimov
http://www.pdplayer.com 

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk