🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Observations on templates

#3340
From: Jason Merrill
Date: Thu, 08 Feb 1996 22:30
70 lines
3966 bytes
>>>>> Eugene Radchenko <eugene@qsar.chem.msu.su> writes:

> jason@cygnus.com (Jason Merrill) writes
>>>>>>> Eugene Radchenko <eugene@qsar.chem.msu.su> writes:

>>> 1) Clause [temp.res] verse 1 requires that all types dependent on the
>>> template parameter must be qualified by 'typename' keyword - supposedly to
>>> allow checking the template syntax. But it does not help anything as _each_
>>> instance will have to be checked anyway:

>> Requiring 'typename' allows syntactic analysis and some name binding
>> to be done at the point of definition of the template.  Older
>> implementations do all name binding at the point of instantiation,
>> which was thought to be confusing.

>> Each instance will indeed have to be checked, but only for semantic
>> correctness, not syntactic.

> And does such a simplification (which does not simplify anything as
> complete recheck is still needed) warrant the introduction of a new
> keyword (why could not at least the 'class' keyword be used like in
> template prefix?).

Because 'class' already has semantics in that position, and a new keyword
is really not a significant problem.  If it conflicts with your code, you
can easily work around it with a #define.

> Interestingly, WRT member functions (and especially operator->) the
> decision was roughly inverse (i.e. to perform checking only on the
> per-instance basis and only if given instance is required).

Nope; function templates, like class templates, are parsed immediately to
do name binding according to the new lookup rules.

>>> 2) Clause [temp.dep] verse 5 states that base class scope names hide the
>>> template parameter:

>> This is for orthogonality.  Think of the template header as creating a
>> special scope around the class; name lookups in class scope look in the
>> current class, then in base classes, then in the surrounding scope.

> That much I do understand. I only think that such an order is
> counter-intuitive.

Well, other people don't, apparently.

>>> 3) Clause [temp.arg.explicit] verses 2-3 requires that for explicit arg in
>>> member template to be present it must be qualified by 'template' keyword,
>>> e.g.
>>> X *p; p->template alloc<200>();
>>> But to use operator -> we need X class definition anyway - so we know that
>>> alloc() is a template.

>> It is needed in some situations where we do not have the X class definition
>> -- in template definitions, like with typename.

> And what are we supposed to do with function alloc() if we do not have the
> class definition and hence do not know anything about this function?

We only need the 'template' keyword there so we know what '<' means.  If
'alloc' is a template, it means "begin template arg list".  Otherwise, it
means "less than", and it doesn't matter if 'alloc' is a function or a
field or an enum or whatever; that can wait until semantic analysis at
instantiation time.

Jason
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
Technical Details
Message-ID: <u9u411zer4.fsf@yorick.cygnus.com>
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern
References: <u9vilu8zvz.fsf@yorick.cygnus.com> <ADqNY6n4sN@qsar.chem.msu.su>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern
From: jason@cygnus.com (Jason Merrill)
Newsgroups: comp.std.c++
Subject: Re: Observations on templates
Date: 08 Feb 1996 14:30:35 PST
Organization: Cygnus Support, Mountain View, CA
Approved: austern@isolde.mti.sgi.com
Message-ID: <u9u411zer4.fsf@yorick.cygnus.com>
References: <u9vilu8zvz.fsf@yorick.cygnus.com> <ADqNY6n4sN@qsar.chem.msu.su>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: 08 Feb 1996 13:30:55 -0800
In-Reply-To: "Eugene Radchenko"'s message of 8 Feb 1996 17:00:57 GMT
X-Newsreader: Gnus v5.0
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMRp5sky4NqrwXLNJAQEdUwIAvQplNB5+N+FIiihbwHnql1OGLHxKM9hY
 x/rrCqKTKtWFZlQOlyNRk+2Tv3/EEyMttjdE3cHMj21c2mcOePJYrA==
 =clXi
Originator: austern@isolde.mti.sgi.com