double hoo(short a, int b) { return 0; }
template<size_t N, typename T> struct argument_type
{
typedef T type;
};
template<typename R, typename A1, typename ...Types> // 가변인자를 처리
struct argument_type<0, R(A1, Types...)>
{
typedef A1 type;
};
template<typename T> void foo(const T& t)
{
// T : double(short, int)
typename argument_type<0, t>::type ret;
// argument_type<0, t> -> 0이 아니라 다른 건 못오나?
cout << typeid(ret).name() << endl;
}
int main()
{
foo(hoo);
}
template<typename R, typename A1, typename ...Types>
struct argument_type<0, R(A1, Types...)>
{
typedef A1 type;
};
template<size_t N, typename R, typename A1, typename ...Types>
struct argument_type<N, R(A1, Types...)>
{
typedef typename argument_type<N-1, R(Types...)>::type type;
};
template<typename T> void foo(const T& t)
{
// T : double(short, int)
typename argument_type<2, t>::type ret;
cout << typeid(ret).name() << endl;
}