By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

Is this a partial specialization issue?

P: n/a
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?

--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:OL********************@speakeasy.net...
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

Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.