Retreive method given object, name and arguments

Michael Coulombe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 11 13:27:51 PDT 2016


Is there a way to implement "getSymbolOfCall" and 
"getDelegateOfCall" such that doit is functionally equivalent to 
calling the method directly?

auto doit(C, string methodName, Args...)(C c, Args args) {
     alias methodSymbol = getSymbolOfCall!(c, methodName, Args);
     pragma(msg, hasUDA!(methodSymbol, "my attr"));
     auto dg = getDelegateOfCall!(c, methodName, Args);
     return dg(args);
}

They should deal with getting the right overload, opDispatch-ing, 
and deducing template arguments from the real argument list to 
get a concrete delegate pointer. methodSymbol should give access 
to compile-time introspection like full signature and UDAs.

The ability to do this for non-member functions would be cool 
too, but is beyond my use case.


More information about the Digitalmars-d-learn mailing list