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

/Jacob Carlborg

On 06 Jul, 2011,at 12:04 AM, Michel Fortin <[email protected]> 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
[email protected]
http://michelf.com/



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

Reply via email to