[dmd-internals] Type-checked arrays!

Jacob Carlborg doob at me.com
Tue Jul 5 23:28:56 PDT 2011


It's possible to emulate properties in C++ with some help of operator overloading: http://en.wikipedia.org/wiki/Property_%28programming%29#C.2B.2B

/Jacob Carlborg

On 06 Jul, 2011,at 12:04 AM, Michel Fortin <michel.fortin at michelf.com> 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.
>
> -- 
> Michel Fortin
> michel.fortin at michelf.com
> http://michelf.com/
>
>
>
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-internals/attachments/20110706/f869afb4/attachment-0001.html>


More information about the dmd-internals mailing list