
On Mon, Jul 5, 2010 at 3:36 PM, Edd Dawson <lists@mr-edd.co.uk> wrote:
On 7/5/2010 8:21 PM, Daniel Walker wrote:
And if you know a signature of a functor, you can use function_types directly with the signature. For example,
template<typename Signature> void f(const boost::function<Signature> &f) { using boost::function_types::parameter_types; using boost::function_types::function_arity;
typedef typename parameter_types<Signature>::type params; // an mpl sequence const std::size_t arity = function_arity<Signature>::value; // ... }
100 bonus points for implementing boost::bind support for me :)
No prob. Yeah, boost::function can store boost::bind objects... if you know the signature. Also, another thought, if the call operators on your function objects are not overloaded, you can do something like the following without having to know the signature. template<typename Functor, typename CallOperator> void f(const Functor &f, CallOperator) { using boost::function_types::parameter_types; using boost::function_types::function_arity; typedef typename parameter_types<CallOperator>::type params; // an mpl sequence const std::size_t arity = function_arity<CallOperator>::value; // ... } struct F { void operator()(int) {} }; int main() { f(F(), &F::operator()); } Daniel Walker