Feature suggestion: in-place append to array

Clemens eriatarka84 at gmail.com
Thu Mar 4 09:29:25 PST 2010


Steven Schveighoffer Wrote:

> int[] a;
> a.setCapacity(10000); // pre-allocate at least 10000 elements.

I would prefer the name reserve(). It has precedent in the STL, and the method doesn't actually always set the capacity, only if the current capacity is less then the argument. Even then it may conceivably allocate more than was asked for.

In other words, the name setCapacity suggests this will always succeed:

a.setCapacity(n);
assert(a.capacity == n);

...which is not the case as far as I can tell.



More information about the Digitalmars-d mailing list