|
Boost Users : |
From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-01-25 13:36:39
Pavel Antokolsky aka Zigmar wrote:
>> 'T' is deduced to a function /pointer/. You have to use the plain
>> function type (without the pointer on top) for 'function_traits' to work:
>>
>> typedef typename boost::function_traits<
>> typename boost::remove_pointer<T>::type >::result_type X;
> Ah, thanks. That what I've been missing. I can of course
> "remove_pointer", but what I'm wandering, is why the function_traits
> tries to add pointer in a first place?
It's done to please broken compilers, I guess.
Further, usually you want to accept both function objects and function
pointers:
template<typename R, typename F> void foo_impl(F f);
template<class F>
inline void foo(F f)
{
typedef typename F::result_type result;
foo_impl<result>(f);
}
template<typename F>
inline void foo(F * f)
{
typedef typename boost::function_traits<F>::result_type result;
foo_impl<result>(f);
}
And if done like this, the function type is deduced without a pointer.
Regards,
Tobias
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