Connecting Tech Pros Worldwide Forums | Help | Site Map

Template template parameters

IR
Guest
 
Posts: n/a
#1: Oct 24 '06
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

Victor Bazarov
Guest
 
Posts: n/a
#2: Oct 24 '06

re: Template template parameters


IR wrote:
Quote:
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.
Quote:
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


IR
Guest
 
Posts: n/a
#3: Oct 24 '06

re: Template template parameters


Victor Bazarov wrote:
Quote:
IR wrote:
[...]
Quote:
Quote:
>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
Greg Comeau
Guest
 
Posts: n/a
#4: Oct 25 '06

re: Template template parameters


In article <Xns9866E3133FB7EZjx3HdoP0Qwt@194.177.96.26>,
IR <no_email@use.netwrote:
Quote:
>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?
Bo Persson
Guest
 
Posts: n/a
#5: Oct 25 '06

re: Template template parameters


IR wrote:
Quote:
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


IR
Guest
 
Posts: n/a
#6: Oct 25 '06

re: Template template parameters


Greg Comeau wrote:

[snip]
Quote:
Quote:
>>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
IR
Guest
 
Posts: n/a
#7: Oct 25 '06

re: Template template parameters


Bo Persson wrote:
Quote:
IR wrote:
[snip]
Quote:
Quote:
>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
Greg Comeau
Guest
 
Posts: n/a
#8: Oct 26 '06

re: Template template parameters


In article <Xns9867E986373FCZjx3HdoP0Qwt@194.177.96.26>,
IR <no_email@use.netwrote:
Quote:
>Greg Comeau wrote:
>
>[snip]
Quote:
Quote:
>>>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?
IR
Guest
 
Posts: n/a
#9: Oct 26 '06

re: Template template parameters


Greg Comeau wrote:

....
Quote:
Quote:
>>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
Closed Thread