std1.0.0-beta-7 SafeC docs

Module collections::static_vec

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

StaticVec<T> / StaticMap<V>: zero-heap collections

Fixed-capacity containers over storage the caller provides — a static array, a stack array, an arena block — so nothing is ever allocated and the capacity is whatever the backing array's (compile-time) size is. Freestanding-safe.

static int g_buf[32];
struct StaticVec<int> v = std::StaticVec::over(g_buf[0..32]);
v.push(42);
?int top = v.pop();

static struct StaticMapSlot<int> g_slots[64];
struct StaticMap<int> m = std::StaticMap::over(g_slots[0..64]);
m.insert(5UL, 100);
int x = m.get(5UL).default(0);

The container holds a slice of the storage: keep the backing array alive at least as long as the container.

Elements may own something (String, Vec, ...): push()/insert() take them by value (a value that doesn't fit is dropped, and updating a StaticMap key drops the old value), pop() moves one out, and clear() drops every element still held. The storage is the caller's, so neither container has a drop() of its own: clear() one whose elements own resources before the storage goes away.

Structs

StaticVec
StaticMapSlot
StaticMap