search of a workaround

Philippe Sigaud philippe.sigaud at gmail.com
Fri Feb 8 23:55:56 PST 2013


On Sat, Feb 9, 2013 at 12:10 AM, monarch_dodra <monarchdodra at gmail.com> wrote:

> Here is a mixin template that *almost* does it:
(...)

> template rvalue(alias fun, string funs)
> {
>     private string ss()
>     {
>         //enum funs = fun.stringof; Don't know how to get function name :(

> See? pretty nice. The only thing missing is actually getting the function
> name :/ I'm not sure how to do it, so I passed two arguments, but it should
> be doable with just 1 (worst case scenario, you pass just the string).

Use __traits(identifier, foo) or std.traits.fullyQualifiedName:

module test;

import std.stdio;
import std.traits;

void foo() { writeln("called!");}

string nameOf(alias f)()
{
    return __traits(identifier, f);
}

void main()
{
    writeln(nameOf!foo);
    writeln(fullyQualifiedName!foo);
}


More information about the Digitalmars-d-learn mailing list