template<class T>
struct TypeX;
template<>
struct TypeX<int(...)>//HERE IF WITHOUT ELLIPSIS IT WILL COMPILE
{
static std::string get_type()
{
return "int()";
}
};
template<>
struct TypeX<int>
{
static std::string get_type()
{
return "int";
}
};
template<class T>
struct type_descriptor
{
typedef T type;
typedef typename std::remove_reference<T>::type no_ref_type;
typedef typename std::remove_pointer<no_ref_type>::type no_ref_no_pointer_type;
typedef typename std::remove_cv<no_ref_no_pointer_type>::type no_ref_no_pointer_no_cv_type;
typedef typename std::remove_all_extents<no_ref_no_pointer_no_cv_type>::type no_ref_no_pointer_no_cv_no_ext_type;
typedef no_ref_no_pointer_no_cv_no_ext_type bare_type;
enum {isArray = std::is_array<T>::value, isPointer = std::is_pointer<T>::value, isRef = std::is_reference<T>::value};
static std::string get_type()
{
return pointer_<isPointer>() + array_<std::is_array<no_ref_no_pointer_type>::value>() + TypeX<bare_type>::get_type();
}
};
template<bool C>
std::string array_()
{return "";}
template<>
std::string array_<true>()
{return "array of";}
template<bool C>
std::string pointer_()
{return "";}
template<>
std::string pointer_<true>()
{return "pointer to";}
int _tmain(int argc, _TCHAR* argv[])
{
cout << type_descriptor<int(*)()>::get_type();
return 0;
}
코드의 주석을 참조하십시오. 문제는 내가 줄임표를 전문적으로 다루는 경우 어떤 숫자를 의미한다고 가정하면 오류가 발생하지만, 인수를 전문으로 만들지 않을 때 컴파일됩니다.템플릿 부분 특수화
설명 할 수 없습니까? main에서 저는 specialization을 사용하려고합니다 : fnc에 대한 포인터는 args를 취하지 않고 int를 반환합니다. –
@ 우리가 할 수있는 일은 없습니다 : 실제로 ''구문은 전문화되지 않습니다. 당신은 이것을해야합니다 : http://www.ideone.com/ah1iH ........ 더 이상의 질문이 있으면 알려주세요! –
Nawaz
@ 우리가 할 수있는 일은 아무것도 없다. 나는 나의 대답을 편집했다. 더 많은 도움이 될만한 것이 있다면 ... http://www.ideone.com/fKxKK – Nawaz