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; };