Boost logo

Boost :

Subject: Re: [boost] boost::bind result type
From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2010-07-19 18:42:00


On Mon, Jul 19, 2010 at 5:37 PM, David Sankel <camior_at_[hidden]> wrote:
> I'm wondering if there's a way I can generically get the result type of
> boost bind.
>
> I'd like to write something along these lines:
>
> template< typename StreamT, typename Sink >
> typename boost::result_of< boost::Bind( StreamT, boost::arg<1>, Sink )
>>::type
> apSink( StreamT t, Sink sk )
> {
>    return boost::bind( t
>                      , _1
>                      , sk
>                      );
> }
>
> I'm not interested in a boost::function solution because I require that uses
> apSink's result can be inlined. Any ideas? Perhaps one of these other
> bind-like libraries has an answer to this.

To my knowledge there is no general way to declare the return type of
boost::bind (or a Boost Lambda expression). In C++03 the best we can
do is boost::function, which can store arbitrary function objects
without having to know the type. In C++0x, the compiler can deduce the
type so that you don't have to declare it.

template< typename StreamT, typename Sink >
auto apSink( StreamT t, Sink sk ) -> decltype(boost::bind(t, _1, sk))
{
   return boost::bind( t
                     , _1
                     , sk
                     );
}

Hope that helps.

Daniel Walker


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