Is this a partial specialization issue?

S

Steven T. Hatton

The subject of templates in C++ is still a weak point for me. If I had
slept in the past 24 hours, I might be able to figure this out myself,
nonetheless, I'll go ahead and ask.

I'm trying to create a type which is formed of a boost::array of
boost::arrays of boost::arrays of 3 float elements. The table below
demonstrates the idea. Assume x, y and z are float:

vf[x, y, z][1, 1] vf[x, y, z][1, 2] vf[x, y, z][1, 3] vf[x, y, z][1, 4]

vf[x, y, z][2, 1] vf[x, y, z][2, 2] vf[x, y, z][2, 3] vf[x, y, z][2, 4]

vf[x, y, z][3, 1] vf[x, y, z][3, 2] vf[x, y, z][3, 3] vf[x, y, z][3, 4]

vf[x, y, z][4, 1] vf[x, y, z][4, 2] vf[x, y, z][4, 3] vf[x, y, z][4, 4]

vf[x, y, z][5, 1] vf[x, y, z][5, 2] vf[x, y, z][5, 3] vf[x, y, z][5, 4]


I want to be able to specify the size when the object is instantiated. The
following results in an error when I try to compile it:

typedef array<float,3> Vec3f;
typedef array<Vec3f> Field3f;

It says mean things such as:

/**************************************************************/
In file included
from /home/hattons/code/c++/gs/vertices/src/vertexfield.cpp:20:
/home/hattons/code/c++/gs/vertices/src/vertexfield.h:27: error: wrong number
of
template arguments (1, should be 2)
/home/hattons/opt/org/boost/include/boost-1_31/boost/array.hpp:38: error:
provided
for `template<class T, unsigned int N> class boost::array'
/**************************************************************/

My compiler is quite pleased with this:
using boost::array;
typedef array<float,3> Vec3f;
const unsigned N=5;
typedef array<Vec3f, N> Field3f;

Is there a way I can create something that acts like a type definition that
accepts a const unsigned when I'm ready to provide it?
 
J

John Harrison

Steven T. Hatton said:
The subject of templates in C++ is still a weak point for me. If I had
slept in the past 24 hours, I might be able to figure this out myself,
nonetheless, I'll go ahead and ask.

I'm trying to create a type which is formed of a boost::array of
boost::arrays of boost::arrays of 3 float elements. The table below
demonstrates the idea. Assume x, y and z are float:

vf[x, y, z][1, 1] vf[x, y, z][1, 2] vf[x, y, z][1, 3] vf[x, y, z][1, 4]

vf[x, y, z][2, 1] vf[x, y, z][2, 2] vf[x, y, z][2, 3] vf[x, y, z][2, 4]

vf[x, y, z][3, 1] vf[x, y, z][3, 2] vf[x, y, z][3, 3] vf[x, y, z][3, 4]

vf[x, y, z][4, 1] vf[x, y, z][4, 2] vf[x, y, z][4, 3] vf[x, y, z][4, 4]

vf[x, y, z][5, 1] vf[x, y, z][5, 2] vf[x, y, z][5, 3] vf[x, y, z][5, 4]


I want to be able to specify the size when the object is instantiated. The
following results in an error when I try to compile it:

typedef array<float,3> Vec3f;
typedef array<Vec3f> Field3f;

It says mean things such as:

/**************************************************************/
In file included
from /home/hattons/code/c++/gs/vertices/src/vertexfield.cpp:20:
/home/hattons/code/c++/gs/vertices/src/vertexfield.h:27: error: wrong number
of
template arguments (1, should be 2)
/home/hattons/opt/org/boost/include/boost-1_31/boost/array.hpp:38: error:
provided
for `template<class T, unsigned int N> class boost::array'
/**************************************************************/

My compiler is quite pleased with this:
using boost::array;
typedef array<float,3> Vec3f;
const unsigned N=5;
typedef array<Vec3f, N> Field3f;

Is there a way I can create something that acts like a type definition that
accepts a const unsigned when I'm ready to provide it?

Templated typedef's are one of the things C++ ought to have but doesn't.
This is illegal

template <unsigned N>
typedef array<Vec3f, N> Field3f;

Field3f<10> a_field_of_ten_vectors;


I think they'll be added one day but for now, you must wrap the typedef
inside a templated class.

template <unsigned N>
struct Field
{
typedef Field3f<N> type;
};

Field<10>::type a_field_of_ten_vectors;

john
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top