🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Vaughn Cato Thu, 24 Aug 1995 10:54
Equivalence of A and A<>
#1834
Author: Vaughn Cato
Date: Thu, 24 Aug 1995 10:54
46 lines
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads