www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - function name inside a funciton

reply "user" <user user.com> writes:
Can someone please tell me how to get a function or method name 
inside that function/method's body? For example ...

void foo(int x) {

    string name = getFunctionName();
    assert(name == "foo");

}


Compile time or runtime either is OK.

Thanks
Apr 11 2014
parent reply "user" <user user.com> writes:
Never mind, just discovered __PRETTY_FUNCTION__.


On Saturday, 12 April 2014 at 02:39:23 UTC, user wrote:
 Can someone please tell me how to get a function or method name 
 inside that function/method's body? For example ...

 void foo(int x) {

    string name = getFunctionName();
    assert(name == "foo");

 }


 Compile time or runtime either is OK.

 Thanks
Apr 11 2014
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 4/12/14, user <user user.com> wrote:
 Never mind, just discovered __PRETTY_FUNCTION__.
Yes and there's also __FUNCTION__. Philippe Sigaud's book[1] had a nice trick of extracting the current function name with a single template instantiation, but I can't find it in his template book. There's a "Local Scope Name" chapter, but I distinctly remember something which was a single template call.. hmm.. it might have changed in recent versions. [1] : https://github.com/PhilippeSigaud/D-templates-tutorial
Apr 11 2014