www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - typeid of a typedef

reply Kramer <Kramer_member pathlink.com> writes:
Given the following code:

file: test.d









It prints this:
char[test.main.string]

If the typedef is done outside of main, it prints this:
char[test.string]

Is this correct functionality?  I would've thought it would just print "string"
instead of the module and/or function name preceding the typedef.

-Kramer
Oct 11 2005
parent "Unknown W. Brackets" <unknown simplemachines.org> writes:
I'm pretty sure that's correct.  That's the fully qualified name of the 
type - every identifier in D is qualified as such internally afaik.

To get the last identifier, you might do something like:

char[] basename(char[] input)
{
    size_t pos = rfind(input, '.');

    if (pos < 0)
       return input;
    else if (pos - 1 >= input.length)
       return null;
    else
       return input[pos + 1 .. input.length];
}

writefln(basename(typeid(typeof(x)).name));

Untested, mind you, but that's the general idea.

-[Unknown]


 Given the following code:
 
 file: test.d

 






 
 It prints this:
 char[test.main.string]
 
 If the typedef is done outside of main, it prints this:
 char[test.string]
 
 Is this correct functionality?  I would've thought it would just print "string"
 instead of the module and/or function name preceding the typedef.
 
 -Kramer
Oct 11 2005