get module name of function

Alex AJ at gmail.com
Sat Mar 30 05:08:48 UTC 2019


How do I get the module name that a function is defined in?

I have a generic template that

auto Do(T)()
{
    pragma(msg, moduleName!T);
}

in a module


and in another module I define a function

void foo() { }

and a class

class C { }

and call Do!(typeof(foo)) and Do!(C)


but it fails for the function. I use type of because it fails 
when I do not.

Is there not some uniform way to treat types like classes and 
functions as the same for meta programming?

If I do

pragma(msg, moduleName!foo);

in the same module as foo it works.

So I guess I have to use Do(alias T)() but then that breaks the 
class(cause I use `isClass`(= is(T == class) wrapper) and it 
complains ;/

I don't understand what the difference between alias and T is.

Alias can be most things and T must be a type, sometimes they 
overlap and sometimes they don't ;/ Is there any way to convert 
one thing to another when they do overlap and to know which 
direction to go?

Do(alias T) or Do(T)?


The second can only take types, the first can take symbolic 
expressions and other stuff but not types?






More information about the Digitalmars-d-learn mailing list