Get rid of inherited enum in partial specialization



 DEVELOP > c-Plus-Plus > Get rid of inherited enum in partial specialization

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "mathieu"
Date: 31 Jan 2008 05:27:07 AM
Object: Get rid of inherited enum in partial specialization
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
.

User: "Ron Natalie"

Title: Re: Get rid of inherited enum in partial specialization 31 Jan 2008 05:58:41 AM
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?
.
User: "mathieu"

Title: Re: Get rid of inherited enum in partial specialization 31 Jan 2008 06:46:18 AM
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 :)
Sorry for the noise
-Mathieu
.
User: "mathieu"

Title: Re: Get rid of inherited enum in partial specialization 31 Jan 2008 07:08:29 AM
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;
}
.




  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER