VecRemove
Description
Remove the element at idx and optionally move its value out to ptr. Order of trailing elements is preserved.
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in,out | Vector handle. |
ptr |
out | Optional destination for the removed element. Pass NULL to discard it (the configured copy_deinit is invoked instead). |
idx |
in | Position in [0, length). |
Success
Returns to the caller. The vector length shrinks by one; elements previously at indices > idx have shifted left by one. When ptr is non-NULL, the removed value has been bit-copied into *ptr (the slot is bit-copied; the copy_deinit handler is NOT called - ownership transfers to the caller). When ptr is NULL and copy_deinit is configured, the handler is invoked on the removed element before the slot is reclaimed.
Failure
Function cannot fail. An out-of-range idx is treated as a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
VecCharPtr.c:108:
size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
char *str;
VecRemove(vec, &str, index);
// char_ptr_deinit is called automatically by the vector
}- In
VecStr.c:130:
size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
Str str;
VecRemove(vec, &str, index);
// StrDeinit is called automatically by the vector
}- In
VecInt.c:78:
if (idx < VecLen(vec)) {
i32 removed;
VecRemove(vec, &removed, idx);
}
break;- In
Remove.h:140:
/// TAGS: Vec, Remove, Pop, Back
///
#define VecPopBack(v, ptr) VecRemove((v), (ptr), (v)->length - 1)
///
- In
Remove.h:158:
/// TAGS: Vec, Remove, Pop, Front
///
#define VecPopFront(v, ptr) VecRemove((v), (ptr), 0)
///
- In
Remove.h:189:
/// TAGS: Vec, Delete
///
#define VecDelete(v, idx) VecRemove((v), (VEC_DATATYPE(v) *)NULL, (idx))
///
- In
Remove.h:42:
/// TAGS: Str, Remove, Char
///
#define StrRemove(str, chr, idx) VecRemove((str), (chr), (idx))
///
Last updated on