It says: .capacity Returns the number of elements that can be appended to the array without reallocating.
This is wrong as the number of elements that can be appended without reallocating is a.capacity - a.length (as described in 12.14.2).
Comment #1 by home — 2023-06-05T05:45:18Z
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.
Comment #2 by robert.schadek — 2024-12-15T15:27:48Z