Open Chrinkus opened 1 year ago
I have struct cgs_strsub
for "slices" of a string, perhaps the equivalent for vectors should be a struct vecsub
? A non-owning view into a vector. Maybe.
As for my initial need, that being AoC 2022 day 5, it seems a splice
function is more appropriate. This would allow me to remove and replace multiple elements if I wanted.
void*
cgs_vector_splice(struct cgs_vector* v, size_t beg, size_t end, struct cgs_vector* reps);
The replacements parameter could be NULL to just cut out the range and be done.
My initial thought is that you provide a read-only source, a start index, an end index, and a writable destination. The indexes will be [start, end) as per most uses of indexes. The user can use -1 for "to the end". Here's the signature:
This will return 'dst' on success and NULL on any kind of failure. And a typical use:
Usability concerns: