[dmd-internals] Type-checked arrays!

Michel Fortin michel.fortin at michelf.com
Tue Jul 5 16:56:26 PDT 2011


Le 2011-07-05 à 18:49, mrmocool at gmx.de a écrit :

>> 	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.
> 
> Is there any sane reason why operator[] can't be used?

It makes refactoring simpler because there's an easily recognizable text pattern "tdata()". Once the current refactoring is done it'll be easy to change it to some other syntax, but currently my focus is on adding type-safety.

And I don't want to start using a C++ feature that isn't used anywhere else in the code base (not without Walter's approval first). Operator overloading isn't used anywhere inside DMD, and operator[] implies returning a '&' reference, another C++ feature not used in the code base (that I know of).

Also, most arrays are actually pointers to an array and I'm not sure how much the [] operator makes things clearer for those:

	Expression *e = (*array)[0];
	(*array)[0] = e;

:-/

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-internals mailing list