Summary: Get the name of function and its parameters
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: Phobos

Phobos should provide an easy and documented way to get the name of the
function and its parameters.

The function name and its parameters are unneeded in "straight" code, but with
mixins and templates it is important. And it's essential for debugging them and
their usage.

Here's some code from D.learn, as a starting point:

// Name of a function?  Yes.

public template NameOfFunc(alias f)
                const char[] NameOfFunc = (&f).stringof[1 .. $];
                const char[] NameOfFunc = (&f).stringof[2 .. $];

        private void _foo_(){}
        static assert(NameOfFunc!(_foo_) == 
            "_foo_", "Oh noes, NameOfFunc needs to be updated.");

// It has to be used at compile time with an alias of course, but it works.
// Name of params?  No, not that I've found.
// Don't you love it?
// "Most C++ template features are discovered."  So are D's.

// Thanks.
// I found that this: 

void main ()
    pragma(msg, typeof(&foo).stringof);

// gave this result:

void function(int x, int y)

// So now I just have to get the names out of there.


Reply via email to