Arkadiy Vertleyb wrote:
"Kirit Sælensminde"
wrote I've been playing around with a few functional programming idioms in C++ using Boost.function and Boost.lambda and was wondering if it was possible to fetch out the argument type (i.e. int) from a type like this:
void (*somefunc)( int )
You don't need any libraries for this -- just use partial template specialization:
template<class T> struct deduce_arg; //not defined
template<class A> struct deduce_arg
{ typedef A0 type; };
This is cool. I'm sure I've tried this sort of thing in MSVC 7.1 before and not had it work. I guess I got the syntax all mixed up. You have a typo in the deduction part. A0 should be A (or A should be A0). It also needs to be a little different to work with the member function (I've added the return type R to the deduction, but the important bit is the extra specialisation): template< typename T > struct deduce_arg; template< typename R, typename A > struct deduce_arg< R (*) (A) > { typedef R ret; typedef A arg1; }; template< typename C, typename R, typename A > struct deduce_arg< R (C::*) (A) > { typedef R ret; typedef A arg1; }; Thanks for the idea. K