Re: Get rid of inherited enum in partial specialization
On Jan 31, 1:46 pm, mathieu <mathieu.malate...@gmail.com> wrote:
On Jan 31, 12:58 pm, Ron Natalie <r...@spamcop.net> wrote:
mathieu wrote:
Hello,
I have the following code:
template<uint16_t Group, uint16_t Element, int TVR, int TVM>
class Attribute
{
public:
enum { VMType = VMToLength<TVM>::Length };
};
template<uint16_t Group, uint16_t Element, int TVR>
class Attribute<Group,Element,TVR,VM::VM1_n>
{
};
what is the best way to get rid of that enum (VMToLength<VM1_n> is not
a valid instantiation) ?
Thanks
-Mathieu
Your question makes no sense. You haven't shown enough of the problem.
There's no inheritance here. What on earth are VM and VMToLength?
And you are very right ! My code was actually:
template<uint16_t Group, uint16_t Element, int TVR =
Default<Group,Element>::ValueTVR , int TVM =
Default<Group,Element>::ValueTVM>
class Attribute { ... };
but because Default<Group,Element>::ValueTVM was expanding to
VM::VM1_n I was expecting the compiler to pick the partially
specialized class :)
And to humilate myself a little more, the compiler is actually picking
the right template class... the error was again in between the chair
and the monitor: Default<Group,Element>::ValueTVM was *not* expanding
to VM::VM1_n
The following code, actually show the proper behavior (*)
Again sorry for the noise
-Mathieu...being more and more amazed at C++ template class
(*)
#include <iostream>
template <int I> struct VMToLength;
typedef enum {
VR1 = 1,
VR2,
} VRType;
typedef enum {
VM1 = 1,
VM2,
VM_N,
} VMType;
template <> struct VMToLength<VM1> { enum { Length = 1 }; };
template <> struct VMToLength<VM2> { enum { Length = 2 }; };
template <unsigned short G, unsigned short E> struct TypeTo;
template <> struct TypeTo<0,0> { enum { VR = VR2 }; enum { VM =
VM2 }; };
template <> struct TypeTo<0,1> { enum { VR = VR1 }; enum { VM =
VM_N }; };
template<unsigned short G, unsigned short E, int TVR =
TypeTo<G,E>::VR, int TVM = TypeTo<G,E>::VM >
class Attribute
{
public:
void foo() { std::cout << "here" << std::endl; }
};
template<unsigned short G, unsigned short E, int TVR>
class Attribute<G,E,TVR,VM_N>
{
public:
void foo() { std::cout << "there" << std::endl; }
};
int main()
{
Attribute<0,0> a;
a.foo();
Attribute<0,1> b;
b.foo();
return 0;
}