From -546580836637708063 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,ede379f5dbbc1549 X-Google-Attributes: gidf78e5,public From: "Greg Brewer" Subject: Re: Suggestion: "typeof" keyword Date: 1999/08/13 Message-ID: <7p1vfa$jnq$1@news.hal-pc.org>#1/1 X-Deja-AN: 512444768 X-NNTP-Posting-Host: dialup-0-39.orbitworld.net Approved: stephen.clamage@sun.com (comp.std.c++) References: <7nt3vl$1oe$1@nnrp1.deja.com> X-UID: 0000000001 X-Priority: 3 X-Status: $$$T X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 Organization: Houston Area League of PC Users, Inc. X-MSMail-Priority: Normal Newsgroups: comp.std.c++ Originator: clamage@taumet wrote in message news:7nt3vl$1oe$1@nnrp1.deja.com... > Suppose I'm writing a template function and II is an unknown > iterator type. How can I refer to the type one gets by > dereferencing an II object? > > In many cases I could say II::value_type, but only if II is > a class that contains a typedef for value_type. What if II is > a simple pointer type? The use of the "typedef ... value_type" > convention in the standard library only highlights the need > for a more universal mechanism. > > I have in mind a keyword, typeof, which would yield the type > of an expression. Like its cousin "sizeof," typeof would not > actually evaluate anything at run-time. > > Does anyone else think such a keyword would be valuable? Or > is this a solution in search of a problem? Following is a > (somewhat contrived) example of how typeof might be used. I think this typeof() function would be doublely useful if it could be used with extra text. Consider, a case I had. I had several structures defined in pairs. The first was the class I used through out my program and the second was a record class that was used to move data to/from a database. There was also operators defined for moving that data. A template was ideal for this operation. Consider one case, class Traits and class Traits_Record; template int StoreInDatabase(T *t) { // at this point, I needed a record. No way to declare one. // perhaps typeof could be designed to handle the problem as follows typeof(*t)##_Record record; // resolves to Traits_Record record; record.StoreData(t); return record.Write(); } Just a consideration, Greg Brewer [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]