[Issue 23967] 12.14 Array Properties - capacity description

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 5 05:45:18 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23967

--- Comment #1 from Franciszek Czekala <home at valentimex.com> ---
However, when you shrink the array a like this: a=a[0..$-1], the subsequent
capacity will show as zero, so there is inconsistency here which looks like a
bug to me.

Example:
int[] a = new int[10];
// a.length == 10, a.capacity == 11
a = a[0..$-1];
// a.length == 9, a.capacity == 0 (???)

Either capacity represents the total number of elements that an array can hold
or it represents the amount of elements that can be appended. As can be seen
above it can be either the former or the latter depending on the context which
seems definitely wrong.

--


More information about the Digitalmars-d-bugs mailing list