
On 7/5/2010 10:46 AM, Edd Dawson wrote:
Hi all,
I'm looking for code that does what boost::function_types::parameter_types does but for functors. Support for things such as boost::bind/lambda/function/signals(1&2)/etc and the standard binders and adaptors would be nice.
I specifically want to be able to do something like:
template<typename Functor> void f(const Functor &f) { typedef typename functor_params<Functor>::type params; // an mpl sequence const std::size_t arity = functor_arity<Functor>::value; // ... }
I started writing code for this but I've come to the point where I can't see a way to support libraries such as boost::bind without relying on their implementation details.
But perhaps something like this already exists?
Thanks,
Edd
At the outset that looks ill-defined, since function objects may generally be polymorphic (accept a variety of parameter types and arities, each combination potentially returning a different result type). For example, struct identity { template< class T > T operator()(T x) const { return x; } }; If you want restrict yourself to monomorphic function objects, then it might be possible, but I don't know of a generic way to obtain the information you're seeking. You can, however, get away with querying whether a function object can be called with a specific signature, though the machinery to do this is relatively complex. I think something working is found in Boost.Proto as "can_be_called". - Jeff