Yet another "compile-time reflection revisited" proposal

Timon Gehr timon.gehr at gmx.ch
Tue Nov 29 13:46:37 PST 2011


On 11/29/2011 09:11 PM, RivenTheMage wrote:
> *1) Replace all symbol-related traits with ".metainfo" property*
>
> __traits(isAbstractClass, A) ==>  A.metainfo.isAbstractClass
>
> __traits(A.func, isVirtualFunction) ==>
> by name: A.metainfo.members["func"].isVirtualFunction
> by index: A.metainfo.members[N].isVirtualFunction
>
> __traits(hasMember, A, "func") ==>  A.metainfo.members.find("func")
>
> Aliasing should be posssible:
> ---
> alias A.metainfo.members mymeta;
> mymeta.find("func");
> ---
>
>
> *2) Replace rest of traits with "meta" keyword*
>
> __traits(compiles, ...) ==>  meta.compiles(...)
>
>
> *4) Add special extendable namespace, accesible through "meta" keyword*
>
> The namespace can be extented by special file "meta.d" which should be a part
> of D runtime. Actually, it's the same thing as std.traits, the intention is
> to put all reflection stuff under one roof.
>
> instead of:
> ---
> import std.traits;
> int foo();
> ReturnType!(foo) x;
> ---
>
> it would be:
> ---
> int foo();
> meta.ReturnType!(foo) x;
> ---
>
>
> *6) Replace identificator-related "is" expressions with ".metainfo" property*
>
> is(Identifier ...) ==>  Identifier.metainfo.isXXX(...)
>
>
> *7) Replace rest of "is" expressions with "meta.is"*
>
> is(...) ==>  meta.isXXX(...)
>
>
> *5) Replace "typeid" keyword with ".typeinfo" property*
>
> typeid(int) ==>  int.typeinfo
> typeid(typeof(x)) ==>  typeof(x).typeinfo
> typeid(i++) ==>  (i++).typeinfo
>
>
> Thoughts?

Yes, __traits should be replaced by a cleaner design eventually. 
'is'-expressions, typeid and std.traits are perfectly fine as they are 
now and I don't see any reason to make their syntax more complicated.

instead of adding .metainfo we could also just add a bunch of enum 
members to the typeinfo obtained by typeid. (that would bundle static 
reflection and rtti). eg. typeid(A).isAbstractClass



More information about the Digitalmars-d mailing list