digitalmars.D - typeid of a typedef
- Kramer (16/16) Oct 11 2005 Given the following code:
- Unknown W. Brackets (16/38) Oct 11 2005 I'm pretty sure that's correct. That's the fully qualified name of the
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
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