🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2134

Re: local type not allowed as template-arg --

#2134
From: Steve Clamage
Date: Fri, 06 Oct 1995 15:26
37 lines
2209 bytes
In article 1bfa@news.doit.wisc.edu, khan@xraylith.wisc.edu (Mumit Khan) writes:
>
>  14.8  Template arguments                                    [temp.arg]
>
>4 Nor is a local type or a type with no linkage name an acceptable  tem-
>  plate-argument.  [Example:
>          void f()
>          {
>              struct S { /* ... */ };                     
>              X<S,p> x3; // error: local type used as template-argument
>          }
>   --end example] 
>
>Why is this necessary? Why isn't the template argument S in X<S,p>
>simply treated as X<f()::S, p> (or something along these lines)?

The problem is "something along those lines". I hope it is clear that the
template parameter would have to be somehow qualified with its scope,
so that some other instantiation with some other type S could be seen
to be a different type.

C++ lacks a mechanism to refer to a local type  outside its scope. Just
qualifying "S" with "f()" would not be enough, because "f()" might be a
static function, and thus there could be other functions "f()" in the program.
If you want to refer to a local type elsewhere, declare the type in a
namespace instead of in a function (thus it is no longer a local type).

So as not to require a method for accessing a local type outside its scope,
templates are not allowed to be instantiated with a local type.
---
Steve Clamage, stephen.clamage@eng.sun.com



[ 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: <453hct$vr@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
References: <4529o8$1bfa@news.doit.wisc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: clamage@Eng.sun.com (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: local type not allowed as template-arg --
Date: 6 Oct 1995 15:26:19 GMT
Organization: Sun Microsystems Inc.
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <453hct$vr@engnews2.Eng.Sun.COM>
References: <4529o8$1bfa@news.doit.wisc.edu>
Reply-To: clamage@Eng
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: taumet.eng.sun.com
Content-Length: 1392
X-Lines: 33
Originator: clamage@taumet