I'm trying to group specializations together to avoid writing them multiple times. For example, in the below code, I try to specialize "float" and "double" as one case of implementation for foo::func(); I then use another implementation for "bool."
template<typename T> struct foo;
template<typename T> struct bar;
template<> struct bar<float> { typedef float Type; };
template<> struct bar<double> { typedef double Type; };
/* specialize for float and double here */
template<typename T> struct foo<typename bar<T>::Type> {
static void func() { ... }
};
template<> struct foo<bool> {
static void func() { ... }
};
This errors out in GCC 4.4.3. (This is a target compiler, because it's stock for Ubuntu Server 10.04 LTS, which allegedly has three more years to live.) The error is:
foo.cpp:8: error: template parameters not used in partial specialization:
foo.cpp:8: error: ‘T’
The error refers to the first specialization of foo (for "float" and "double.")
I don't see what part of C++ I'm violating here -- if anyone knows the chapter and verse, I'd appreciate it. Also, if someone knows of another way of accomplishing the same goal (re-using specializations for certain groups of types, without unnecessarily verbose code,) I'd also appreciate any suggestions!