Static Array

Simple API over static array buffer allocated on stack.

Example

#import "std/static_array"

main :: fn () s32 {
	using std;

	arr: StaticArray(s32, 10);
	loop i := 0; i < 10; i += 1 {
		sarray_push(&arr, i);
	}

	sarray_erase(&arr, 1);
	sarray_erase(&arr, 4);

	loop i := 0; i < arr.len; i += 1 {
		print("%\n", arr.data[i]);
	}
	return 0;
}

std.StaticArray

StaticArray :: fn (TElem: type, elem_count: s64) type

Create Static Array type.

StaticArray :: struct {
    data[elem_count]TElem;
    len: s64;
}

File: static_array.bl

std.sarray_push

sarray_push :: fn { 
    impl_push_empty; 
    impl_push; 
}

Push element at the end of the array and returns its address.

Warning: Asserts in case there is not enough space left in the storage.

File: static_array.bl

std.sarray_pop

sarray_pop :: fn (arr: *?TArr, out : *: null) bool #inline

Pops the last element of the array into out destination and returns true otherwise returns false and value of out stays unchanged.

File: static_array.bl

std.sarray_erase

sarray_erase :: fn (arr: *?TArr, i: s64) 

Errase element at the index i. The index value must be valid in range 0 <= i < len.

File: static_array.bl

std.sarray_clear

sarray_clear :: fn (arr: *?TArr)  #inline

Clear the array.

File: static_array.bl

std.sarray_get_slice

sarray_get_slice :: fn (arr: *?TArr) [] #inline

Get the content of static array as an slice.

File: static_array.bl

std.sarray_typeof_elem

sarray_typeof_elem :: fn (TArr: type) type

Return type of the element.

File: static_array.bl