fill

Assigns elements to an array.

The function is a replacement for declaring an array literal, it does not allocate GC memory and ensures the length of the array matches the number of variadic arguments.

void
fill
(
T
)
(
T[] array
,)

Parameters

T

the type of array element

array T[]

the array to assign the elements to

elements T[]

the elements to add to the array

Examples

int[10] array;

auto previous_ptr = array.ptr;
testNoAlloc(array.fill(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
test!("is")(previous_ptr, array.ptr);

foreach (i, item; array)
    test!("==")(array[i], item);
int[] array;

array.length = 10;
assumeSafeAppend(array);

auto previous_ptr = array.ptr;
testNoAlloc(array.fill(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
test!("is")(previous_ptr, array.ptr);

foreach (i, item; array)
    test!("==")(array[i], item);

Meta