type vectorable { std; /* this would be needed for comparisons like find() or something */ comparable; } type vec {t: vectorable} { std_vector: void; len: usize; buf: 't; } pub define vec(t) { struct (vec{t}) } pub init(v: 'vector) { v.len = 0; v.buf = null; } pub length(v: *vec => usize) { return v.len; } pub index(v: *vec, i: usize => '#v.buf) { assert(i < v.len, "index %zu out of bounds\n", i); return &v.buf[i]; } pub index(v: mut *vec, i: const isize => '#v.buf) { if i < 0 { assert(-i < v.len, "reverse index %zi out of bounds\n", i); return &v.buf[v.len + i]; } assert(i < v.len, "index %zi out of bounds\n", i); return &v.buf[i]; } pub prepend(v: mut 'vec, e: '#v.buf) { insert(v, e, 0); } pub append(v: mut 'vec, e: '#v.buf) { insert(v, e, v.len); } pub preplace(v: mut 'vec, e: '#v.buf) { place(v, e, 0); } pub applace(v: mut 'vec, e: '#v.buf) { place(v, e, v.len - 1); } pub place(v: mut *vec, e: '#v.buf, i: usize) { } pub insert(v: mut *vec, e^ '#v.buf, i: usize) { } pub deinit(mut v *vec) { for i usize : v { deinit(v[i]); v[i] = null; } dealloc(v.buf); }