
Do function_traits work with functors? I tried with struct XYZ { bool operator() (int x) const { return x+2; } }; template<typename FUNCTION> class BindingImpl1xxx { public: typedef FUNCTION function; typedef typename boost::function_traits<FUNCTION>::result_type res_type; typedef typename boost::function_traits<FUNCTION>::arg1_type arg1_type; }; but the following won't compile: XYZ xyz; BindingImpl1xxx<XYZ> xxx(xyz); Is there a way to achieve the function_traits functionality with function_traits or some other type_traits? Thank you. Christoph

AMDG Christoph wrote:
Do function_traits work with functors?
I tried with
struct XYZ { bool operator() (int x) const { return x+2; } };
<snip>
Err, what do you want to happen for an overloaded or templated function object? struct f { template<class T> void operator()(const T&) const; };
Is there a way to achieve the function_traits functionality with function_traits or some other type_traits?
You can try typedef BOOST_TYPEOF(FUNCTION::operator()) mf_type; Then mf_type will be (e.g.) int (XYZ::*)(int) const, which can be broken down by the Function Types library. In Christ, Steven Watanabe

Steven Watanabe wrote:
AMDG
Christoph wrote:
Do function_traits work with functors?
<snip>
Err, what do you want to happen for an overloaded or templated function object? Indeed, I was thinking of the simple case of non-overloaded, non-templated functors.
typedef BOOST_TYPEOF(FUNCTION::operator()) mf_type;
Then mf_type will be (e.g.) int (XYZ::*)(int) const, which can be broken down by the Function Types library. I'll look into that. Maybe I can create a Boost.Function from the functor and use some of Boost.Function's typedefs?
Thank you.

Hi christoph, Did you try providing a result_type typedef in your function object as shown below? Christoph wrote:
Do function_traits work with functors?
I tried with
struct XYZ {
typedef bool result_type;
bool operator() (int x) const { return x+2; } };
Jeff Flinn
participants (4)
-
Christoph
-
Christoph Duelli
-
Jeff Flinn
-
Steven Watanabe