I'm don't understand why template specialization is different for variadic templates than for regular (i.e., non-variadic) templates. For example I have a template and a specialization like:
enum class MF : int {
ZERO = 0,
ONE = 1,
TWO = 2
};
// --------- Specialization -------------
template <MF mf>
class Stat{
public:
Stat(std::string msg) {
cout << "Generic Stat construtor: " << msg << endl;
}
};
// --------- Template Specialization -------------
template<>
class Stat<MF::ONE>{
public:
Stat(std::string msg) {
cout << "Specialized Stat constructor: " << msg << endl;
}
};
I have specialized with a specific value of the MF
enumeration.
Now if I want to specialize a variadic template I can't specialize the variadic template parameters with a specific value of the MF
enumeration (e.g., MF::ONE
), I can only specialize with a type, (e.g. MF
).
// --------- Variadic Template -------------
template<MF mf, typename... E>
class Var{
public:
Var(std::string msg){
cout << "Generic Var constructor: " << msg << endl;
}
};
// --------- Variadic Template Specialization -------------
template<>
class Var<MF::TWO, MF>{
public:
Var(std::string msg){
cout << "Specialized Var constructor: " << msg << endl;
}
};
I would like to specialize my variadic template for a specific MF
value, but it doesn't appear that I can.
Is there some aspect of the language that I'm missing that would allow me to do what I want? Something along the lines of:
template<>
class Var<MF::TWO, MF::ONE>{
public:
Var(std::string msg){
cout << "Specialized Var constructor: " << msg << endl;
}
};
Complete example can be found here
but it doesn't appear that I can.
do you get an error or anything? – Sebastian HoffmannMF::ONE
atypename
? Then, why do you expect to be able to pass it to atypename...
? – Yakk - Adam NevraumontMF::ONE
is an enumerate value. – jlconlinclass Var<MF::TWO, MF::ONE>
. I get this errorerror: template argument for template type parameter must be a type class Var<MF::TWO, MF::ONE>{
– jlconlin