Reed's standard library. Imported with use std.vec; not on disk.
comptime func vec_search_of(T: type, Name: ident)
Adds equality-based searching to a vector generated by vec_of.
Separate from vec_of because == requires numeric operands (spec section 7): these methods do not compile for a reference element type, so emitting them unconditionally would make every comptime vec_of(?Point, ...) a hard error.
Instantiate it directly after the vec_of it extends, with the same Name:
comptime vec_of(i32, IntVec, int_vec);
comptime vec_search_of(i32, IntVec);
Generates the methods index_of, contains, count_of, and equals.
- Parameters
- T — the element type; must be numeric
- Name — the vector type
vec_of generated
- See also
vec_of
comptime func vec_of(T: type, Name: ident, prefix: ident)
Declares a growable vector of T named Name, with constructors prefixed prefix.
Generates:
array <Name>Storage { mut T } -- the backing array.
struct <Name> -- the vector itself, an array plus a length.
func new_<prefix>() -> &<Name> and
func new_<prefix>_with_capacity(capacity: i32) -> &<Name>.
- Methods
len, capacity, is_empty, reserve, push, pop, at, get_or,
set, insert, remove, clear, truncate, swap, reverse, extend, clone, and to_array.
Capacity doubles, so n pushes cost O(n) copying in total rather than O(n^2). Nothing here traps except at with an out-of-range index, which matches std.list's convention: a computed offset clamps, a direct index is a caller bug.
- Parameters
- T — the element type; must be defaultable (numeric, or a nullable
?Foo)
- Name — the PascalCase name for the generated vector type
- prefix — the snake_case prefix for the generated constructor functions
- See also
vec_search_of