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で私は特殊化を使用しようとしています:fncへのポインタはゼロの引数を取ってintを返します。 –
@私たちは何もできません:実際には、文法「」は特殊化には使用できません。あなたはこれをやろうとしています:http://www.ideone.com/ah1iH ........私はあなたにさらなる質問があれば教えてください! –
Nawaz
@私たちは何もできません。答えを編集しました。これらの例をあげれば、どれくらいの利点があるのか教えてください。http://www.ideone.com/fKxKK – Nawaz