I've always thought it should be done with a template:

   typedef ArrayOf<Expression> Expressions;

On 7/5/2011 3:04 PM, Michel Fortin wrote:
I've made a new branch of the DMD compiler to replace the currently type-unsafe 
Array type with arrays that can be type-checked by the compiler. It's not ready 
for a pull request yet, but I'd like to hear some comments.

Take a look at the changes:
<https://github.com/michelf/dmd/compare/master...type-checked-arrays>

The basic goal is that you no longer have to cast to the right type when 
getting something out of an array (except for some exceptional cases). In 
arraytypes.h you define an array of the type you need using the ArrayOf macro 
like this:

        struct Expression;

        typedef ArrayOf(Expression) Expressions;

And voilĂ ! you have a type-safe array-of-Expression type. Instead of accessing 
the 'data' member directly, you now access 'tdata()' (for typed-data) which 
gets you a properly typed pointer:

        Expression *e = array->tdata()[0];
        array->tdata()[0] = e;

I know it's ugly, but unfortunately C++ doesn't have properties. I'm open to 
suggestions.

_______________________________________________
dmd-internals mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/dmd-internals

Reply via email to