1
模板专业化我有一个包含关于类型的性状的结构:为模板类型
template<typename T> struct x_trait { static const bool has_x = true; };
这是对所有类型的,但一定模板类型正确。对于某些模板类型,我想更改特征:
template<> struct x_trait<tt_type<int>> { static const bool has_x = false; };
到目前为止,这么好。但tt_type
本身采用不同的模板参数。有没有办法为所有模板化的tt_type
设置x_trait
?现在我出去唯一的办法就是列出所有的类型:
template<> struct x_trait<tt_type<char>> { static const bool has_x = false; };
template<> struct x_trait<tt_type<short>> { static const bool has_x = false; };
template<> struct x_trait<tt_type<int>> { static const bool has_x = false; };
template<> struct x_trait<tt_type<long>> { static const bool has_x = false; };