array.length++ not an lvalue

Fawzi Mohamed fmohamed at mac.com
Wed Jun 18 08:11:39 PDT 2008


On 2008-06-18 16:30:39 +0200, "Koroskin Denis" <2korden at gmail.com> said:

> [some nice points]
> D *could* do the following trick:
> array.length()+=1 -> array.length(array.length() + 1);
> 
> but it would break too much of the existing code and makes a little of  sense.

actually I think that in some cases for properties it makes sense (for 
example for my slices of multidimensional arrays) and does not break 
code *but* normally it defeats the performance reason to do +=.
In fact it is a good idea not to hide things that have a speed penalty, 
and the extra typing is minimal.

In the case of the length property this is very much so.
Arrays are not the correct data structure for step by step resizes... 
either try to have the correct size from the beginning, or switch 
datastructure.




More information about the Digitalmars-d mailing list