www.digitalmars.com         C & C++   DMDScript  

D - typeof equivalent?

reply Russell Lewis <spamhole-2001-07-16 deming-os.org> writes:
Does DMD or DLI implement an equivalent of gcc's typeof() operator?  I 
think that something like this should be a part of the language spec. 
It's very useful, at times.
Nov 12 2002
next sibling parent reply Burton Radons <loth users.sourceforge.net> writes:
Russell Lewis wrote:
 Does DMD or DLI implement an equivalent of gcc's typeof() operator?  I 
 think that something like this should be a part of the language spec. 
 It's very useful, at times.

".typeinfo" for a TypeInfo instance, ".classinfo" for a ClassInfo instance. If you mean for declarations: typeof (x) y; Then no, there's nothing of the sort. What are you trying to use it in?
Nov 12 2002
next sibling parent reply Evan McClanahan <evan dontSPAMaltarinteractive.com> writes:
Burton Radons wrote:
 Russell Lewis wrote:
 
 Does DMD or DLI implement an equivalent of gcc's typeof() operator?  I 
 think that something like this should be a part of the language spec. 
 It's very useful, at times.

".typeinfo" for a TypeInfo instance, ".classinfo" for a ClassInfo instance. If you mean for declarations: typeof (x) y; Then no, there's nothing of the sort. What are you trying to use it in?

are .typeinfo and .classinfo documented anywhere? It would be nice to have some more solid information on them, and I can't find it anywnere in the spec. Evan
Nov 12 2002
parent "Walter" <walter digitalmars.com> writes:
"Evan McClanahan" <evan dontSPAMaltarinteractive.com> wrote in message
news:aqrfas$j2k$1 digitaldaemon.com...
 are .typeinfo and .classinfo documented anywhere?  It would be nice to
 have some more solid information on them, and I can't find it anywnere
 in the spec.

They're in phobos/object.d, but you're right, they need to be better documented.
Dec 15 2002
prev sibling parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Burton Radons wrote:

 Russell Lewis wrote:
 Does DMD or DLI implement an equivalent of gcc's typeof() operator?  I
 think that something like this should be a part of the language spec.
 It's very useful, at times.

".typeinfo" for a TypeInfo instance, ".classinfo" for a ClassInfo instance. If you mean for declarations: typeof (x) y; Then no, there's nothing of the sort. What are you trying to use it in?

Came across this again. I had an automatically generated type. The program that references it doesn't know anything about the type, or its type name, except that it is an array of structs, and some of the member names inside the struct. The user code can do this: for(int b=0; b<foo.bars.length; b++) DoStuff(foo.bars[b].baz); I would like to decare, in user code, an array of the same type without requiring that the user code know the internal naming scheme of the code generator. Something like this: typeof(foo.bars[0])[] mySlice = foo.bars[2..5]; As far as I can see, there is no good alternative to typeof() here...anything else requires that the user code know the internal naming scheme of the code generator. -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Apr 05 2003
parent "Mike Wynn" <mike.wynn l8night.co.uk> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3E8EDE59.DABF2286 deming-os.org...
 Burton Radons wrote:

 Russell Lewis wrote:
 Does DMD or DLI implement an equivalent of gcc's typeof() operator?  I
 think that something like this should be a part of the language spec.
 It's very useful, at times.

".typeinfo" for a TypeInfo instance, ".classinfo" for a ClassInfo instance. If you mean for declarations: typeof (x) y; Then no, there's nothing of the sort. What are you trying to use it in?

Came across this again. I had an automatically generated type. The

 that references it doesn't know anything about the type, or its type name,
 except that it is an array of structs, and some of the member names inside
 the struct.

 The user code can do this:

     for(int b=0; b<foo.bars.length; b++)
         DoStuff(foo.bars[b].baz);

 I would like to decare, in user code, an array of the same type without
 requiring that the user code know the internal naming scheme of the code
 generator.  Something like this:

     typeof(foo.bars[0])[] mySlice = foo.bars[2..5];

 As far as I can see, there is no good alternative to typeof()
 here...anything else requires that the user code know the internal naming
 scheme of the code generator.

I started thinking along these lines .... how about a template with a value type thus; // the generated type; struct gen_type_001 { ... } // generated template template gen_array( gen_type_001 match ) { alias gen_type_001 []array_type; } // another generated type and template. struct gen_type_002 { ... } template gen_array( gen_type_002 match ) { alias gen_type_002 []array_type; } then realised ...
     for(int b=0; b<foo.bars.length; b++)
         DoStuff(foo.bars[b].baz);
  typeof(foo.bars[0])[] mySlice = foo.bars[2..5];

whats foo where is it declared. statically typed langs require it to be declared somewhere visible to the user. the obvious solution is to use a hashtable `Object[char[]] map` so foo.bars is a Object[char[]] [] (think that's right : array of assoc array (maps char[] to Object) and use foo.bars[b]["baz"]
Apr 05 2003
prev sibling parent Lloyd Dupont <lloyd galador.net> writes:
Russell Lewis wrote:

 Does DMD or DLI implement an equivalent of gcc's typeof() operator?  I
 think that something like this should be a part of the language spec.
 It's very useful, at times.

Nov 12 2002