Bug 23967 – 12.14 Array Properties - capacity description

Status
NEW
Severity
minor
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2023-06-05T05:24:20Z
Last change time
2024-12-15T15:27:48Z
Assigned to
No Owner
Creator
Franciszek Czekala
Moved to GitHub: dlang.org#4131 →

Comments

Comment #0 by home — 2023-06-05T05:24:20Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dlang.org/issues/4131 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB