how to pass a variable name in the template in this case?

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Aug 2 15:36:21 PDT 2012


On 8/3/12, Zhenya <zheny at list.ru> wrote:
> snip

You mean how to extract the variable name?

import std.stdio;

template T(alias a)
{
    enum string T = __traits(identifier, a);
}

void main(string[] argv)
{
    char f = 'a';
    writeln(T!f);  // writes 'f'
}


More information about the Digitalmars-d-learn mailing list