changing array lengths
Jarrett Billingsley
jarrett.billingsley at gmail.com
Tue Dec 9 21:54:13 PST 2008
On Tue, Dec 9, 2008 at 11:54 PM, Ellery Newcomer
<ellery-newcomer at utulsa.edu> wrote:
> Does the following totally not make sense? I think it should work.
>
> int[] a = new int[10];
>
> a.length += 30;
>
It's a weird limitation that's been around forever. Ugh.
Here, have this.
T[] resize(T)(ref T[] arr, ptrdiff_t delta)
{
arr.length = arr.length + delta;
return arr;
}
...
auto a = new int[10];
a.resize(30); // now 40
a.resize(-30); // now 10
More information about the Digitalmars-d-learn
mailing list