|
Boost : |
Subject: Re: [boost] boost::bind result type
From: Edd Dawson (lists_at_[hidden])
Date: 2010-07-20 16:13:54
Hi David,
On 7/19/2010 10:37 PM, David Sankel wrote:
> 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
> );
> }
According to the bind docs, if StreamT is a function object, it needs to have a
result_type to be compatible with bind. If StreamT is a function or member
function you can use the function_types::result_type<> meta-function.
So could you not write a meta-function that asks if its parameter is a function
(once any pointer and reference baggage has been removed) and if so, use
function_types::result_type<>, else just use the result_type member which has to
be there anyway?
Something like this:
// entirely untested
template<typename F>
struct functor_result_type
{
typedef typename F::result_type type;
};
template<typename F>
struct strip_function :
remove_pointer<typename remove_reference<F>::type>
{
};
template<typename F>
struct bindable_result_type :
mpl::eval_if
<
is_function<typename strip_function<F>::type>,
function_types::result_type<F>,
functor_result_type<F>
>
{
};
Then:
template<typename StreamT, typename Sink>
typename bindable_result_type<StreamT>::type
apSink(StreamT t, Sink sk)
{
return boost::bind(t, _1, sk);
}
Any good?
Kind regards,
Edd
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk