Reflection: is type an inner class
Tyler Jameson Little
beatgammit at gmail.com
Sat Oct 20 19:17:55 PDT 2012
Say I have something like this:
class A {
class B {
}
B b;
}
Right now, I have a loop that does something like this (taken
from orange project):
foreach (i, type; typeof(A.tupleof)) {
enum name = A.tupleof[i].stringof[1 + A.stringof.length +
2 .. $];
}
This gets all members of class A (in this case only b), but I
can't 'new' the class because it needs the context of the
instance of A. So, I need to check (preferably at compile time)
if b's type is an inner class or an outer class. If it's an inner
class, I'll need to instantiate it with the reference of A.
std.traits doesn't seem to have anything useful. I'd like to know
the following:
* is b's type instantiatable (is that a word?) without extra
information?
* is b's type an inner class (needs reference to instantiate)
In my code, I have a reference handy, so I just need to know how
to instantiate it.
I saw the macro 'compiles' in the traits documentation
(__traits(compiles, ...)). Do I need to do something with this?
More information about the Digitalmars-d-learn
mailing list