Article View: comp.std.c++
Article #1834Equivalence of A and A<>
From: Vaughn Cato
Date: Thu, 24 Aug 1995 10:54
Date: Thu, 24 Aug 1995 10:54
46 lines
2465 bytes
2465 bytes
I am curious as to the reasoning behind disallowing the use of a template
name as a synonym for a template id with no template parameters:
template <class T = int> class A;
void f()
{
A<> *p1; // The legal way to default the argument
A *p2; // Syntax error
}
Now that the complex class in the standard library has been templatized,
there has been some concern over breaking existing code using it as a
non-template class. It seems that the proper way to handle this would be
to have the default for the template parameter be double, and any template
name A to be a synonym for A<> if not followed by '<' when used as a type
name. If this was the case, then you would have the following:
template <class T = int> class A;
template <class T> class B;
int main()
{
A<> *p1; // OK (means A<int>)
A *p2; // OK (means A<int>)
B<> *p3; // Invalid number of template arguments
B *p3; // Invalid number of template arguments
}
There is probably a good reason why this wasn't allowed that I am
overlooking. The only reason I have been able to determine so far
is that it was an attempt to make a clear distinction between the class
template as a whole, and a specific template class. This parallels with
the function call syntax, which requires ()'s to be used even when no
actual parameters are passed. However, I haven't been able to determine
any concrete problems the above change would introduce, such as ambiguities
or incompatibilities with other parts of the language. It seems that if
the above syntax was valid, it would solve the general problem of
class generalization to templates that I have seen in many instances.
Thank you,
Vaughn Cato (gcato@st6000.sct.edu)
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<9508240412.AA27932@st6000.sct.edu>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 24 Aug 95 10:54:30 GMT Approved: fjh@cs.mu.oz.au Newsgroups: comp.std.c++ Return-Path: <daemon@ncar.UCAR.EDU> Message-ID: <9508240412.AA27932@st6000.sct.edu> Subject: Equivalence of A and A<> X-Original-Date: Thu, 24 Aug 1995 00:12:00 -0400 (EDT) From: gcato@st6000.sct.edu (Vaughn Cato) X-Mailer: ELM [version 2.4 PL23] Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Length: 1708