Getting typeid/tuple of context (struct/class/function)

KlausO oberhofer at users.sf.net
Wed Apr 18 08:48:12 PDT 2007


Hi D experts,

I'm trying to make some generic logging code and thought
that more runtime type/tuple information would be helpful.
Take the following example

<code>
module testtypeid;

import std.stdio;

struct Outer
{
   static void func()
   {
     // want to log the context name
     writefln(typeid(Outer));      // this works
     // writefln(typeid(func));       // does not work

     // how to do this in a generic way ?
     // writefln(typeid(current_context));
     // writefln(typeid(current_context.parent));
   }
}

void main()
{
   Outer.func();
}
</code>

Some thoughts/questions:
1. typeid(Outer) works because structs supports typeinfo's

2. typeid(func) doesn't work because no typeinfo available for static 
functions. Maybe there is the possibility to get there with 
templates/tuples ?

3. Is there a way to get the typeinfo/tuple of the current context 
(function, struct, class, module) an expression is in ?

Maybe this gets easy when AST macros are available ?
Thanks


KlausO


More information about the Digitalmars-d-learn mailing list