🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: typename versus typedef (was Re: typedef X;)

#2032
From: Alex Martelli
Date: Mon, 25 Sep 1995 17:26
66 lines
3040 bytes
ark@research.att.com (Andrew Koenig) writes:

>In article <MATT.95Sep23125440@Austern>
>martelli@cadlab.cadlab.it (Alex Martelli) writes:

>> avoiding the template author the chore of thinking up a dummy type
>> name in this situation...?  Or am I missing something here...?

>You're missing something.

>	template<class T> class X {
>		int a;
>		void f() {
>			T::Pointer (a);		// *
>		}
>	};

>If T::Pointer is the name of a type, the line with the comment
>declares a local variable inside function f that is of type T::Pointer.
>If, on the other hand, T::Pointer is the name of a function, then
>the line with the comment calls that function passing it the
>member names `a' of class X.

So far, so clear.

>This shows that in general it is necessary for the compiler to know
>whether each identifier is the name of a type.  In the case of members
>of template parameters, there's no easy way to know that in advance,
>so the "typename" keyword provides a way to say.

And if typename is absent, then T::Pointer will be taken for not
a typename, right?

So, what would be wrong with the idiom I suggested could have been
used instead -- if T::Pointer is used as in your example, take it
as not a typename; if you need to use a type name qualified by a
template parameter class, you would then have to write:

	void f() {
	    typedef T::Pointer anyoldname;
	    anyoldname a;
	}

This _is_ unambiguous, isn't it?  T::Pointer _must_ be a type name
in this usage -- unless I'm missing something here, which I think
you still have not shown.

Is typename just syntactic sugar for something that could have been
obtained with a not-particularly-obscure idiom for this situation?
That's what I was asking when I asked "what happened to minimalism".
I guess there must be some reason to make the typedef-idiom substitute
for "typename" not workable or not desirable, but, what IS it?


Alex
--
DISCLAIMER: these are TOTALLY personal opinions and viewpoints, NOT connected
in any way with my employer, nor any other organization or individual!
Email: martelli@cadlab.it                            Phone: +39 (51) 597313
CAD.LAB s.p.a., v. Ronzani 7/29, Casalecchio, Italia   Fax: +39 (51) 597120

---
[ 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: <MATT.95Sep25102656@physics2.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <Etay_Bogner-1709951504510001@metay_pc.stil.scitex.com> <MATT.95Sep20135311@physics2.Berkeley.EDU> <MATT.95Sep23125440@Austern> <DFFJz3.GB@research.att.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: martelli@cadlab.cadlab.it (Alex Martelli)
Newsgroups: comp.std.c++
Subject: Re: typename versus typedef (was Re: typedef X;)
Date: 25 Sep 1995 17:26:56 GMT
Organization: Cad.Lab Spa, Bologna, Italia
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <MATT.95Sep25102656@physics2.Berkeley.EDU>
References: <Etay_Bogner-1709951504510001@metay_pc.stil.scitex.com> <MATT.95Sep20135311@physics2.Berkeley.EDU> <MATT.95Sep23125440@Austern> <DFFJz3.GB@research.att.com>
NNTP-Posting-Host: physics2.berkeley.edu