Hi, I'm trying really hard to made this work, but I'm having no luck. I'm sure there is a work around, but I haven't run across it yet. Alright, let's see if I can describe the problem and the needs simply enough:
I have a RGB template class that can take typenames as one of its template parameters. It takes the typename and sends it into another template that creates a classification of its basic type. For example:
struct float_type {};
struct bit_type {};
struct fixed_pt_type {};
template <typename T> struct type_specification { typedef float_type type; };
template <> struct type_specification<char> { typedef bit_type type; };
template <> struct type_specification<short> { typedef bit_type type; };
template <> struct type_specification<int> { typedef bit_type type; };
template <> struct type_specification<long> { typedef bit_type type; };
template <> struct type_specification<long long> { typedef bit_type type; };
Then with this, I have a template that calculates Max Values for each of the RGB values based on its bit count:
template <int Bits, typename T> struct Max_Values { enum { MaxValue = (1 << Bits) - 1; }; };
template <int Bits> struct MaxValues<float_type> { enum { MaxValue = 1.0; }; };
Then in the actual RGB template class, I have:
enum
{
RMax = Max_Values<RBits, type_specification<T>::type>::MaxValue;
GMax = Max_Values<GBits, type_specification<T>::type>::MaxValue;
BMax = Max_Values<BBits, type_specification<T>::type>::MaxValue;
};
This works really well for me, until I got into the fixed-pt needs. The max value is a bit different and I don't know how to create a type-specification specialization to isolate it out. The only work around I have is the process of elimination and creating specializations for float and double and assuming the general case will be fixed-pt. But there has to be a better way to do this. Here is what I want to do with incorrect code:
template <> struct type_specification<fixed_pt_t> { typedef fixed_pt_type type; };
However, fixed-pt-t is a template class that looks like:
template <int N, typename T, template <class> class Policy> struct fixed_pt_t
So the compiler does not like the specialization without template parameters.
Is there a way to specialize my type-specification class to work with fixed-pt-t?
It works fine for the general case, just can't isolate it.