473,385 Members | 2,243 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,385 software developers and data experts.

Templates within templates

Is it possible to write something like

template<class T1, class T2>
class CMyClass {
typedef T1<T2> mynewtype; // key line using too of the template
parameters to create a third type
mynewtype x;
}

typedef CMyClass<vector, int> mynewclass;

I have tried but it does not recognise T1 as a templated class even though
the one I am instantiating it with is. The real thing is too big to paste
but the example shows the key line i want to do. I am assuming I need to
say that T1 should be a template but cannot find how to do it, something
like

template<template class T1, class T2>

Thanks in advance for any responses,

Tom
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 22 '05 #1
2 1099
Tom McCallum wrote:
Is it possible to write something like

template<class T1, class T2>
class CMyClass {
typedef T1<T2> mynewtype; // key line using too of the template
For that you need to declare T1 a template, not a class.
parameters to create a third type
mynewtype x;
}

typedef CMyClass<vector, int> mynewclass;

I have tried but it does not recognise T1 as a templated class even
though the one I am instantiating it with is. The real thing is too big
to paste but the example shows the key line i want to do. I am assuming
I need to say that T1 should be a template but cannot find how to do it,
something like

template<template class T1, class T2>


That's right. However, in order to use 'std::vector' there, you need
to provide the correct template argument list:

template<template<class T,class = std::allocator<T> > class T1,
class T2>
class CMyClass
{
typedef T1<T2> mynewtype;
};

...

CMyClass<std::vector, int> cmc_v_i;
Victor
Jul 22 '05 #2
On Wed, 04 Aug 2004 15:59:19 GMT, Tom McCallum
<te********@hotmail.com> wrote:
Is it possible to write something like

template<class T1, class T2>
You need
template<template<class> class T1, class T2>
class CMyClass {
typedef T1<T2> mynewtype; // key line using too of the template
parameters to create a third type
mynewtype x;
}

typedef CMyClass<vector, int> mynewclass;
Ahh, that still won't work since vector takes 2 template parameters
(the second is the allocator). Which means that you need something
like:

template<
template<class, class> class T1,
class T2>
class CMyClass
{
typedef T1<T2, std::allocator<T2> > mynewtype;
mynewtype x;
};
I have tried but it does not recognise T1 as a templated class even though
the one I am instantiating it with is. The real thing is too big to paste
but the example shows the key line i want to do. I am assuming I need to
say that T1 should be a template but cannot find how to do it, something
like

template<template class T1, class T2>


Yup, you were close.

Tom
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vince C. | last post by:
Hi all, I've created XML documents that are described with a schema. I'm using those documents to create web pages. All my web pages contain a fixed header and a variable document part. The...
5
by: Tom Alsberg | last post by:
Hi there... I'm recently trying to get a bit acquainted with XML Schemas and XSL. Now, I have a few questions about XSL stylesheets and templates: * Is there a way to "enter" a child element...
5
by: david hepworth | last post by:
Hi All I will try to explain my problem. I am wishing to apply a template to the following XML. There are multiple event nodes within the register root node. For each of the event nodes there...
2
by: parksch2 | last post by:
Quick question: How would I nest the apply templates on the following XML structure? /ITEM/CHILD/ITEM/CHILD/ITEM/CHILD I would first like to apply templates on /ITEM/CHILD. Within that...
1
by: Leslaw Bieniasz | last post by:
Cracow, 15.09.2004 Hi, I am writing a big C++ project using BCB 4.0. The project consists of several dlls and exes. Each of the dll is composed of several units (that is cpp files with...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
11
by: Elpoca | last post by:
Hi: What rules govern the inlining of templated functions and templated class methods? It has always been my understanding that both templated functions and templated class methods were...
25
by: Ted | last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because they were rejected in comp.lang.c++.moderated. It behooves anyone reading them to first read the the thread of the...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.