Thread overview
typeof equivalent?
Nov 12, 2002
Russell Lewis
Nov 12, 2002
Burton Radons
Nov 12, 2002
Evan McClanahan
Dec 15, 2002
Walter
Apr 05, 2003
Russ Lewis
Apr 05, 2003
Mike Wynn
Nov 12, 2002
Lloyd Dupont
November 12, 2002
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.

November 12, 2002
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?

November 12, 2002
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

November 12, 2002
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.
>
myObject.classinfo

December 15, 2002
"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.


April 05, 2003
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))) ]


April 05, 2003
"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
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.
>

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"]