DMD 1.005 release
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Sun Feb 11 09:40:00 PST 2007
Jarrett Billingsley wrote:
> "Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message
> news:eqcmo3$2u17$1 at digitaldaemon.com...
>
> Just wanted to add that something I find severely lacking is that there's no
> way to get a pretty (usable, non-mangled) string representation of a type.
> Instead we have to write large template libraries to accomplish something
> that the compiler does _all the time_. This means it's currently not
> possible to do something like
>
> template MakeVariable(Type, char[] name)
> {
> const char[] MakeVariable = Type.nameof ~ " " ~ name ~ ";";
> }
>
> mixin(MakeVariable!(int, "x"));
>
> Instead we have to use a template library to demangle the name:
>
> import ddl.meta.nameof;
>
> template MakeVariable(Type, char[] name)
> {
> const char[] MakeVariable = prettytypeof!(Type) ~ " " ~ name ~ ";";
> }
>
> mixin(MakeVariable!(int, "x"));
>
>
> :\
>
>
Well, actually you can do that, with the unannounced (in the changelog)
.stringof property ( http://www.digitalmars.com/d/property.html ) :
----
template MakeVariable(Type, char[] name)
{
const char[] MakeVariable = Type.stringof ~ " " ~ name ~ ";";
}
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-announce
mailing list