推 CrimsonLunar:印象中是不行 01/04 19:30
// 一個只有型別資訊的結構
template<class Char, class Trait = std::char_traits<Char> >
struct Field
{
typedef Char char_type;
typedef Trait char_trait;
typedef std::basic_string<Char> string_type;
};
// 簡化 std::vector 的樣板定義,只是方便使用
template<class V>
struct vector{
enum { value = 'v' };
};
// 理由同上
template<class K, class V>
struct map{
enum { value = 'm' };
};
// 不應該被推導出來的型別
template<typename F, typename T>
struct judge;
// 針對 vector
template<typename F, template<class> class C>
struct judge< F, C<F> >
{
typedef C<F> Container;
};
// 針對 map
template<typename F, template<class, class> class C>
struct judge< F, C<typename F::string_type, F> >
{
typedef C<typename F::string_type, F> Container;
};
int main()
{
typedef Field<unsigned char> myField;
judge<myField, vector>::Container fieldVec;
judge<myField, map>::Container fieldMap;
}
GCC 一直推導出
type/value mismatch at argument 2 in template parameter list for
'template<class F, class T> struct judge
所以 template template 偏特化是不可能的嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.47.70.23