473,503 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Template template parameters

IR
Hello,

Does anyone know why this declaration compiles:

template< template<typenameclass T>
class X { /*...*/ };

while this one doesn't:

template< template<typenametypename T>
class X { /*...*/ };
I thought "class" and "typename" were equivalent in template
declarations?

I don't think it's my compiler's fault (VC8) because I couldn't find
references to syntaxes like the second one on the web, only like the
first one, so there must be a logical reason...

Even Comeau's FAQ uses the first form, without even mentioning the
second one.

Thanks by advance.

--
IR
Oct 24 '06 #1
8 1787
IR wrote:
Hello,

Does anyone know why this declaration compiles:

template< template<typenameclass T>
class X { /*...*/ };

while this one doesn't:

template< template<typenametypename T>
class X { /*...*/ };
I thought "class" and "typename" were equivalent in template
declarations?
They are, but only if you use them alone. What you have here is
a template template argument and you cannot use 'typename' there,
it has to be 'class'. See 14.1/1 for the syntax.
I don't think it's my compiler's fault (VC8) because I couldn't find
references to syntaxes like the second one on the web, only like the
first one, so there must be a logical reason...

Even Comeau's FAQ uses the first form, without even mentioning the
second one.
Because there is no "second one". The syntax rules require "class"
there.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 24 '06 #2
IR
Victor Bazarov wrote:
IR wrote:
[...]
>I thought "class" and "typename" were equivalent in template
declarations?

They are, but only if you use them alone. What you have here is
a template template argument and you cannot use 'typename' there,
it has to be 'class'. See 14.1/1 for the syntax.
[...]

Thanks for the answer Victor.
From now on I'll try to look _also_ in the standard before posting
stupid questions on a newsgroup... ;-)

Cheers.
--
IR
Oct 24 '06 #3
In article <Xn**************************@194.177.96.26>,
IR <no******@use.netwrote:
>Does anyone know why this declaration compiles:

template< template<typenameclass T>
class X { /*...*/ };

while this one doesn't:

template< template<typenametypename T>
class X { /*...*/ };
I thought "class" and "typename" were equivalent in template
declarations?

I don't think it's my compiler's fault (VC8) because I couldn't find
references to syntaxes like the second one on the web, only like the
first one, so there must be a logical reason...

Even Comeau's FAQ uses the first form, without even mentioning the
second one.
If I understand you, there is no second one. See revision at:

http://www.comeaucomputing.com/techtalk/#typename
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in beta!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Oct 25 '06 #4
IR wrote:
Hello,

Does anyone know why this declaration compiles:

template< template<typenameclass T>
class X { /*...*/ };

while this one doesn't:

template< template<typenametypename T>
class X { /*...*/ };
I thought "class" and "typename" were equivalent in template
declarations?
No, they are not. In some places they are eqivalent, in others they
are not. You found one of those!

The opposite example is

template<class T, typename T::some_type>
stuct X;

Here, the class keyword can be replaces by typename, but the typename
in the second parameter cannot be replaced by class.

So, using typename in place of class can be confusing!
Bo Persson
Oct 25 '06 #5
IR
Greg Comeau wrote:

[snip]
>>Even Comeau's FAQ uses the first form, without even mentioning the
second one.

If I understand you, there is no second one. See revision at:

http://www.comeaucomputing.com/techtalk/#typename
I was rather refering to the template template section :
http://www.comeaucomputing.com/techtalk/templates/#ttp

which clearly uses

template <template <typename Tclass Product>...

whereas it uses typename everywhere else.

--
IR
Oct 25 '06 #6
IR
Bo Persson wrote:
IR wrote:
[snip]
>I thought "class" and "typename" were equivalent in template
declarations?

No, they are not. In some places they are eqivalent, in others
they are not. You found one of those!

The opposite example is

template<class T, typename T::some_type>
stuct X;

Here, the class keyword can be replaces by typename, but the
typename in the second parameter cannot be replaced by class.
Isn't this very example a (non-)dependent name lookup disambiguation?
(or whatever it is called... I guess you get the point anyway :p)

--
IR
Oct 25 '06 #7
In article <Xn**************************@194.177.96.26>,
IR <no******@use.netwrote:
>Greg Comeau wrote:

[snip]
>>>Even Comeau's FAQ uses the first form, without even mentioning the
second one.

If I understand you, there is no second one. See revision at:

http://www.comeaucomputing.com/techtalk/#typename

I was rather refering to the template template section :
http://www.comeaucomputing.com/techtalk/templates/#ttp

which clearly uses

template <template <typename Tclass Product>...

whereas it uses typename everywhere else.
Then see http://www.comeaucomputing.com/techt...ates/#typename :)
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in beta!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Oct 26 '06 #8
IR
Greg Comeau wrote:

....
>>I was rather refering to the template template section :
http://www.comeaucomputing.com/techtalk/templates/#ttp

which clearly uses

template <template <typename Tclass Product>...

whereas it uses typename everywhere else.

Then see
http://www.comeaucomputing.com/techt...ates/#typename :)
Oops my bad, I didn't see it yesterday. :)

--
IR
Oct 26 '06 #9

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

Similar topics

3
1994
by: Gianni Mariani | last post by:
I was a little surprised by this: It seems like the code below should not compile but the Comeau 4.3.3 compiler accepts it and the gcc 3.4(prerel) compiler rejects it and MSVC++7.1 ICE's. ...
11
2484
by: Alexander Stippler | last post by:
Hi, I have a little problem to design some template classes in a realizable way. I have some Container classes and some Proxy classes (proxies for elements). Looks like this: // P is the...
3
1725
by: Erik Wikström | last post by:
I've been trying for a while now to understand how template template parameters work. But I just can't wrap my head around it and was hoping that someone might help me. As best I can figure the...
6
2789
by: rincewind | last post by:
Hi, can anybody summarise all options for partial template specialization, for all kind of parameters (type, nontype, template)? I *think* I understand options for partial specialization on...
4
3075
by: Dan Krantz | last post by:
I have the following template to ensure that a given number (val) falls into a range (between vmin & vmax): template<typename T> T ForceNumericRange( const T& val, const T& vmin, const T& vmax)...
8
3848
by: Paul Roberts | last post by:
Hi, I'm hoping somebody here can help me with a simple problem of template syntax. Here's an example: template<typename T, int iclass A { static int a;
8
5302
by: Jess | last post by:
Hi, I have a template function that triggered some compiler error. The abridged version of the class and function is: #include<memory> using namespace std; template <class T>
2
1906
by: Pierre Yves | last post by:
Hi there, Sorry for the double subject but I feel they are related. I'm not pretty sure there would be an answer but I reckon there must be a way to make it work. I would like to write the...
8
2933
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
4
3013
by: * Tong * | last post by:
First of all, thanks mlimber for answering my previous question. Now... I'm following the example in "C++ Templates: The Complete Guide", section 5.4 Template Template Parameters, and I'm...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
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
7271
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
7319
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...
1
6979
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
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5570
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
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.