Get name of alias parameter at compile time?

Denis Koroskin 2korden at gmail.com
Thu Oct 15 07:27:03 PDT 2009


On Thu, 15 Oct 2009 18:22:37 +0400, dsimcha <dsimcha at yahoo.com> wrote:

> Jacob Carlborg Wrote:
>
>> On 10/14/09 06:36, dsimcha wrote:
>> > Is there a way to get the name of an alias parameter at compile  
>> time?  For
>> > example:
>> >
>> > void doStuff() {
>> >      // Do stuff.
>> > }
>> >
>> > void templ(alias fun)() {
>> >     writeln(fun.stringof);  // Prints doStuff.
>> > }
>>
>> Do you want that to print "fun" instead of "doStuff"?
>
> No, the whole point is that I want to print "doStuff".

What's the big deal?

import std.stdio;

void doStuff() {
}

void templ(alias fun)() {
     writeln(fun.stringof);   // prints "main()"
}

void main()
{
     templ!(main);
}

Works for both D1 and D2



More information about the Digitalmars-d mailing list