October 12, 2005
Given the following code:

file: test.d
# import std.stdio;

# void main(char[][] args)
# {
#     typedef char[] string;
#     char[string] x;
#     writefln(typeid(typeof(x)));
# }

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


October 12, 2005
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
> # import std.stdio;
> 
> # void main(char[][] args)
> # {
> #     typedef char[] string;
> #     char[string] x;
> #     writefln(typeid(typeof(x)));
> # }
> 
> 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