access enclosing type from shared static this()

"Øivind" oivind.loe at gmail.com
Wed Sep 19 12:37:35 PDT 2012


I want to access the type of the enclosing struct in in a shared 
static initializer.. How do I do that? The following code will 
not compile:

mixin template MsgMixin(T ...) {
   static string getName(this M)() {
     return M.stringof;
   }
   shared static this() {
     import std.stdio;
     writeln("register " ~ getName());
   }
}

struct MsgTestMsg {
   mixin MsgMixin!();
}

I get the following error messages:

src/main.d(40): Error: template 
main.MsgTestMsg.MsgMixin!().getName does not match any function 
template declaration
src/main.d(40): Error: template 
main.MsgTestMsg.MsgMixin!().getName(this M) cannot deduce 
template function from argument types !()()

If not possible, just getting the name of the enclosing struct 
would help a lot!

-Øivind



More information about the Digitalmars-d-learn mailing list