Hello,
Does anyone know why this declaration compiles:
template< template<typena meclass T>
class X { /*...*/ };
while this one doesn't:
template< template<typena metypename 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 8 1797
IR wrote:
Hello,
Does anyone know why this declaration compiles:
template< template<typena meclass T>
class X { /*...*/ };
while this one doesn't:
template< template<typena metypename 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
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
In article <Xn************ **************@ 194.177.96.26>,
IR <no******@use.n etwrote:
>Does anyone know why this declaration compiles:
template< template<typena meclass T> class X { /*...*/ };
while this one doesn't:
template< template<typena metypename 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?
IR wrote:
Hello,
Does anyone know why this declaration compiles:
template< template<typena meclass T>
class X { /*...*/ };
while this one doesn't:
template< template<typena metypename 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
14.6.1 in the standard seems to imply that template parameters are
hidden by class members.
struct X
|
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 Proxy class.
template <typename T, typename P>
class Container
{
|
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 code should look
something like this:
template<template<typename S> typename T>
struct element_traits {
typedef S type;
};
|
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 type
parameters - in place of a template argument one can construct arbitrary
valid C++ type declaration, more or less like in "typedef" statement.
What about nontype parameters? Am I right that you cannot partially
|
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)
{
T retVal = val;
if ( retVal < vmin )
retVal = vmin;
| |
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;
|
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>
|
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 following bit of code:
8<----------------------------
|
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
{
// ...
};
|
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 wondering if it's
basics/stack8.hpp example can be compiled under g++ 4.
First a bit background about template template:
5.4 Template Template Parameters
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |