Chances of D getting proper runtime reflection?

Jacob Carlborg doob at me.com
Thu Aug 25 01:49:52 PDT 2011


On 2011-08-25 06:30, Martin Nowak wrote:
> It is actually already possible to store meta data in classinfos.
>
> ---
> import std.stdio;
>
> class A {
> int a;
> float b;
> }
>
> mixin template register(T) if(is(T == class)) {
> static this() {
> T.classinfo.m_offTi = [OffsetTypeInfo(0, typeid(int)), OffsetTypeInfo(4,
> typeid(float))];
> }
> }
>
> mixin register!A;
>
> void main() {
> foreach(offTi; A.classinfo.offTi())
> writeln(offTi.offset, offTi.ti);
> }
> ---
>
> The compiler doesn't initialize the m_offTi array. But classinfos are in
> the initialized data section, at least for me, so you can write to them.
>
> martin

Seems to be very unsafe to rely on m_offTi in ClassInfo.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list