Basic module

pop

procedure · 1 overloadSource

Removes the last element and returns it. Fails an assert when the array is empty.

Only the count is lowered, so a pointer taken to the element earlier still reads its old value until the slot is reused.

ExampleOpen in playground ↗
values: [..] int;
array_add(*values, 1, 2, 3);
assert(pop(*values) == 3 && pop(*values) == 2);
assert(values.count == 1);
array_free(values);
pop :: (array: *[] $T) -> T

Removes the last element and returns it. Fails an assert when the array is empty.

Only the count is lowered, so a pointer taken to the element earlier still reads its old value until the slot is reused.

Parameters

array: *[] $T

Returns

T
ExampleOpen in playground ↗
values: [..] int;
array_add(*values, 1, 2, 3);
assert(pop(*values) == 3 && pop(*values) == 2);
assert(values.count == 1);
array_free(values);

See also