why MemberFunctionsTuple not support struct ?

Newbie2019 newbie2019 at gmail.com
Tue Jul 30 11:33:07 UTC 2019


I need to get the struct method ( function member)  address on 
reflection,  do some search and find MemberFunctionsTuple, but it 
only for class.

I think D need a traits for get struct method delegate address.  
I see there is no nice workaround.

like:  __traits(allMethods, C),   __traits(getMethod, C, name)

struct method delegate address is a function pointer const, so 
can be use on compile time like function address.

The problem is I can't get it on runtime easy,  D will think I 
try call the method and return the method return type.

alias KillCallback = scope bool delegate();

struct S {
     bool kill() {
      return true;
    }
}

pragma(msg, typeof(__traits(getMember, S, "kill")) ); // bool()
pragma(msg, typeof(KillCallback.init.funcptr)); // bool function()
enum IS_SAME = __traits(isSame,   typeof(__traits(getMember, S, 
"kill")), typeof(KillCallback.init.funcptr) );

static assert(IS_SAME);











More information about the Digitalmars-d mailing list