Newbie needs help with traits

D

Dick Bridges

I'm still struggling with templates [and mpl?]. If someone could point me
toward books or articles or tutorials that discuss how to achieve the
following, I'd very much appreciate it.

I'd like to create a traits template [MyClsTraits] to be used by some class
[MyCls]. For example, suppose I've inherited (i.e., have no control over)
the following #defineS.

#define X_ONE 1
#define X_TWO 2

#define Y_ONE 1
#define Y_TWO 2

And I'd like to be able to declare an instance like this.
MyClsTraits<X_TWO, Y_ONE> t;
such that t has two traits: X_ and Y_ that are then used by MyCls<t>.

Additionally, I need to be able to control the allowable combinations. IOW:
X_TWO/Y_ONE is legal but X_ONE/Y_TWO is not a valid combination and produces
a compilation or link error.

TIA Any relevant references would be appreciated.
 
R

red floyd

Dick said:
I'm still struggling with templates [and mpl?]. If someone could point me
toward books or articles or tutorials that discuss how to achieve the
following, I'd very much appreciate it.

I'd like to create a traits template [MyClsTraits] to be used by some class
[MyCls]. For example, suppose I've inherited (i.e., have no control over)
the following #defineS.

#define X_ONE 1
#define X_TWO 2

#define Y_ONE 1
#define Y_TWO 2

And I'd like to be able to declare an instance like this.
MyClsTraits<X_TWO, Y_ONE> t;
such that t has two traits: X_ and Y_ that are then used by MyCls<t>.

Additionally, I need to be able to control the allowable combinations. IOW:
X_TWO/Y_ONE is legal but X_ONE/Y_TWO is not a valid combination and produces
a compilation or link error.

TIA Any relevant references would be appreciated.

create a specialization for MyClsTraits<X_ONE,Y_TWO> with any and all constructors private?
 
D

Dick Bridges

red floyd said:
Dick said:
I'm still struggling with templates [and mpl?]. If someone could point me
toward books or articles or tutorials that discuss how to achieve the
following, I'd very much appreciate it.

I'd like to create a traits template [MyClsTraits] to be used by some class
[MyCls]. For example, suppose I've inherited (i.e., have no control over)
the following #defineS.

#define X_ONE 1
#define X_TWO 2

#define Y_ONE 1
#define Y_TWO 2

And I'd like to be able to declare an instance like this.
MyClsTraits<X_TWO, Y_ONE> t;
such that t has two traits: X_ and Y_ that are then used by MyCls<t>.

Additionally, I need to be able to control the allowable combinations. IOW:
X_TWO/Y_ONE is legal but X_ONE/Y_TWO is not a valid combination and produces
a compilation or link error.

TIA Any relevant references would be appreciated.

create a specialization for MyClsTraits<X_ONE,Y_TWO> with any and all constructors private?

Thanks for the response.

Thing is, the 'real' traits has four sets of values and each set has ~20 to
~40 possible values. Is there no way to accomplish this with something
like, for example, mpl typelists?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top