Possible to partially typedef templates?

E

esuvs81

Hi all, i have a Vector class (as in mathematical vectors) which is
templatised on two parameters, the length of the vector and it's type
(int,double,etc). I am able to use a typedef like the folowing:

typedef Vector<3,float> Vector3DFloat;
Vector3DFloat myVector;

so that users can now use Vector3DFloat as a type in thier code.
However, i would like to just typedef away *one* of the parameters
which i would expect to look something like the following:

typedef Vector<3,Type> Vector3D<Type>;
Vector3D<float> myVector;

The above doesn'tcompile but hopefully illustrates what I am trying to
do. Is there a way to make this work?

Thanks,

David
 
J

jpalecek

(e-mail address removed) napsal:
Hi all, i have a Vector class (as in mathematical vectors) which is
templatised on two parameters, the length of the vector and it's type
(int,double,etc). I am able to use a typedef like the folowing:

typedef Vector<3,float> Vector3DFloat;
Vector3DFloat myVector;

so that users can now use Vector3DFloat as a type in thier code.
However, i would like to just typedef away *one* of the parameters
which i would expect to look something like the following:

typedef Vector<3,Type> Vector3D<Type>;
Vector3D<float> myVector;

The above doesn'tcompile but hopefully illustrates what I am trying to
do. Is there a way to make this work?

No, there's no elegant solution to this. C++0x will (hopefully) have
"template
typedefs", which is just what you want. If you want further details
including possible workarounds, see
http://www.ddj.com/dept/cpp/184403850

Regards
Jiri Palecek
 
A

amparikh

Hi all, i have a Vector class (as in mathematical vectors) which is
templatised on two parameters, the length of the vector and it's type
(int,double,etc). I am able to use a typedef like the folowing:

typedef Vector<3,float> Vector3DFloat;
Vector3DFloat myVector;

so that users can now use Vector3DFloat as a type in thier code.
However, i would like to just typedef away *one* of the parameters
which i would expect to look something like the following:

typedef Vector<3,Type> Vector3D<Type>;
Vector3D<float> myVector;

The above doesn'tcompile but hopefully illustrates what I am trying to
do. Is there a way to make this work?

Thanks,

David

You cannot typedef templates with the template parameters. However you
can simulate the effect by introducing an intermediate type.
You can refer to Herb Sutter's GOTW here..

http://www.gotw.ca/gotw/079.htm
 
E

esuvs81

Ok, thanks to both of you. It looks like i can get around the problem
with Herb Sutters solution until C++0x arrives...

Thanks again,

David
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top