std1.0.0-beta-7 SafeC docs

Module collections::slice

#include <std/collections/slice.h> source

Slice<T>: a bounds-checked view of T elements

int arr[8];
struct Slice<int> s = std::Slice::from(arr[0..8]);
int third = s.get(2UL).default(0);
struct Slice<int> mid = s.sub(2UL, 5UL);   // elements 2,3,4
[]int raw = s.as_slice();                  // back to the built-in slice

The language's own []T is the buffer type std's APIs take and return; Slice<T> is a library view on top of it with checked get/set/sub, and the way to view a heap array from 'new T[n]' (Slice::of(first, n): the caller vouches for n) or allocate one (Slice::alloc). A Slice doesn't own its elements unless it came from Slice::alloc() (then free() releases them). The arr_* helpers below work on a []T directly.

Structs

Slice

Functions

arr_at
arr_set
arr_fill
arr_copyCopies min(dst.len, src.len) elements; returns that count.
arr_minSmallest / largest element by '<'; null for an empty slice.
arr_max
arr_reverse