Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to convert a function variable to a string in D?

Tags:

function

mixins

d

Is there any way, given a function variable, to get the name of the function as a string? For example, if I have:

void function(int) func;

Is there some function x() such that I could get:

x(func) == "func";

? I feel like this would be possible using mixins, but I'm confused as to how to implement this.

like image 712
Mark LeMoine Avatar asked Jun 21 '11 07:06

Mark LeMoine


1 Answers

func.stringof

is what you need.

You could also make a template:

template Name(alias Func) { enum Name = Func.stringof; }

void func() { }
pragma(msg, Name!(func));    //prints func()
like image 147
user541686 Avatar answered Oct 11 '22 16:10

user541686