compile time class introspection?

Jarrett Billingsley kb3ctd2 at yahoo.com
Fri Jun 15 05:06:30 PDT 2007


"Serg Kovrov" <kovrov at bugmenot.com> wrote in message 
news:f4sfn7$spe$1 at digitalmars.com...
>
> I sincerely hope that in 2.0 specs all workarounds and side-effects will 
> be properly (re)designed and will become rather features.
>

I agree with this in many cases.  Using the is() expressions to extract type 
info like function return/param types and classes' base classes seems kind 
of hackish.  I'd much rather see type properties expanded, so function types 
would have .returnType and .paramTypes, classes would have .baseClasses and 
.methodsof (as well as a way to get the _names_ of those methods, and the 
fields while we're at it).

Furthermore, I think type trait detection is particularly weird.  To detect 
whether a type is a static array, Tango uses the following template:

template isStaticArrayType( T )
{
    const bool isStaticArrayType =
    is( typeof(T.init)[(T).sizeof / typeof(T.init).sizeof] == T );
}

Okay, now we have to instantiate this template time and time again to see if 
it's a static array, even though *the compiler already knows the answer*. 
The same goes for all those other type trait templates.  It just seems like 
a suboptimal solution. 





More information about the Digitalmars-d mailing list