Given any functor, I'd like to pull out the type of the first parameter that it takes. It can be assumed that the functor takes only one parameter. I can do this with functions, but am looking for a solution for functors.
#include <iostream>
#include <utility>
template <typename T>
struct test;
template <typename R, typename P>
struct test<R(*)(P)>
{
typedef R R_t;
typedef P P_t;
};
void fn(int value)
{
std::cout << "function called " << value << std::endl;
}
int main()
{
using namespace std;
cout << typeid(test<decltype(&fn)>::R_t).name() << endl;
cout << typeid(test<decltype(&fn)>::P_t).name() << endl;
}