473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Is this a partial specialization issue?

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
1 1087

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
9
by: Philip Lawatsch | last post by:
Hi I'd like to implement some kind if type traits myself, but I have to support broken compilers (like visual studio) that do not support Partial Specialization. My first shot was something...
8
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I...
1
by: BekTek | last post by:
I'm still confused about the template partial specialization which is used in many libraries.. due to lack of introduction for beginner.. Could you tell me about that in short? Thanks in...
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
2
by: Michael Stembera | last post by:
Here is a very simple piece of code to repro this bug. template<typename T, int N> inline bool foo( void ) { return true; } template<typename T> inline bool foo<T, 1>( void ) { return...
4
by: Alfonso Morra | last post by:
Does VC 7.1 support template specialization and partial specialization ?
6
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T foo<true, T>(T val) { return(val); } But both gave...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
9
by: Greg | last post by:
Hi, I would like to specify behavior of a class member relatively to template implemetation. It works in usual cases but it seems to fail with to templates when one of the two is specified... ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.