<html><body><div>It's possible to emulate properties in C++ with some help of operator overloading: http://en.wikipedia.org/wiki/Property_%28programming%29#C.2B2B<br></div><div><br></div><div>/Jacob Carlborg<br></div><div><br>On 06 Jul, 2011,at 12:04 AM, Michel Fortin <michel.fortin@michelf.com> wrote:<br><br><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch">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.<br>
<br>
Take a look at the changes:<br>
<<a href="https://github.com/michelf/dmd/compare/master...type-checked-arrays" _mce_href="https://github.com/michelf/dmd/compare/master...type-checked-arrays">https://github.com/michelf/dmd/compare/master...type-checked-arrays</a>><br>
<br>
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:<br>
<br>
        struct Expression;<br>
<br>
        typedef ArrayOf(Expression) Expressions;<br>
<br>
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:<br>
<br>
        Expression *e = array->tdata()[0];<br>
        array->tdata()[0] = e;<br>
<br>
I know it's ugly, but unfortunately C++ doesn't have properties. I'm open to suggestions.<br>
<br>
-- <br>
Michel Fortin<br>
<a href="mailto:michel.fortin@michelf.com" _mce_href="mailto:michel.fortin@michelf.com">michel.fortin@michelf.com</a><br>
<a href="http://michelf.com/" _mce_href="http://michelf.com/">http://michelf.com/</a><br>
<br>
<br>
<br>
_______________________________________________<br>
dmd-internals mailing list<br>
<a href="mailto:dmd-internals@puremagic.com" _mce_href="mailto:dmd-internals@puremagic.com">dmd-internals@puremagic.com</a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/dmd-internals" _mce_href="http://lists.puremagic.com/mailman/listinfo/dmd-internals">http://lists.puremagic.com/mailman/listinfo/dmd-internals</a><br>
</div></div></blockquote></div></div></body></html>