Unification and extension of compile-time reflection

Steven Schveighoffer schveiguy at yahoo.com
Tue Nov 25 05:42:55 PST 2008


Jarrett,

I agree with most of what you are saying, except for this:

"Jarrett Billingsley" wrote
> Secondly - the type properties are cute but they're not very flexible.
> They can interfere with fields and methods, and so the compiler has
> to explicitly check that aggregate member names don't step on the
> built-in property names.  I think that "T.prop" could just be replaced
> with "traits(prop, T)".  traits(min, int), and so on.  Yes, it's
> longer - but that's what templates are for, if you really want it
> shorter: Min!(int).

Ugh!  Can we just change traits to not use the functional style?

I like as others have suggested:

C.traits.isVirtualMethod(foo);

substitute traits for your favorite reflection keyword (how about traitsof?)

There is also one other benefit to min and max (and others) being first 
class properties.  You can mimic their behavior in user-defined types.  For 
example, if int.min is changed to traits(min, int) or even int.traits.min, 
then how do I define a similar 'minimum' for say, a time type, which would 
be totally arbitrary.

According to the spec, the only builtin properties that user defined types 
have are init, sizeof, alignof, mangleof, stringof.  With the exception of 
init, most of these are pretty uncommon member names.

I wouldn't mind moving init into traits (with the above syntax):

C.traits.init

The other properties are specific to the builtin types, and therefore cannot 
conflict with members.

-Steve 





More information about the Digitalmars-d mailing list