You can partially specialise the x_trait
template for all specialisations of the tt_type
template:
template<typename T>
struct x_trait<tt_type<T>> { static const bool has_x = false; };
Question
I have a struct that contains a trait about a type:
template<typename T> struct x_trait { static const bool has_x = true; };
That is correct for all types but for a certain template type. For that certain template type I want to change the trait:
template<> struct x_trait<tt_type<int>> { static const bool has_x = false; };
So far, so good. But the tt_type
itself takes different template parameters. Is there a way to set the x_trait
for all templated tt_type
s? Right now my only way out is to list all types:
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; };
Solution
You can partially specialise the x_trait
template for all specialisations of the tt_type
template:
template<typename T>
struct x_trait<tt_type<T>> { static const bool has_x = false; };