_d_arraysetlengthT

fnsize_t _d_arraysetlengthT(Tarr : T[], T)(return ref scope Tarr arr, size_t newlength) @trusted

Resize a dynamic array by setting its .length property.

Newly created elements are initialized based on their default value. If the array's elements initialize to 0, memory is zeroed out. Otherwise, elements are explicitly initialized.

This function handles memory allocation, expansion, and initialization while maintaining array integrity.

void main()
{
   int[] a = [1, 2];
   a.length = 3; // Gets lowered to `_d_arraysetlengthT!(int)(a, 3, false)`
}

Parameters

arrThe array to resize.
newlengthThe new value for the array's .length.

Returns

The resized array with updated length and properly initialized elements.

Throws

OutOfMemoryError if allocation fails.