VecPopFront
Description
Remove and optionally return the first element of the vector. Order of trailing elements is preserved.
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in,out | Vector handle. |
ptr |
out | Optional destination for the popped element. Pass NULL to just delete it (the configured copy_deinit is invoked instead). |
Success
Returns to the caller. The vector length shrinks by one; all remaining elements have shifted left by one. When ptr is non-NULL the removed value is bit-copied into *ptr.
Failure
Function cannot fail. Calling on an empty vector is a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
VecCharPtr.c:86:
if (VecLen(vec) > 0) {
char *str;
VecPopFront(vec, &str);
// char_ptr_deinit is called automatically by the vector
}- In
VecStr.c:111:
if (VecLen(vec) > 0) {
Str str;
VecPopFront(vec, &str);
// StrDeinit is called automatically by the vector
}- In
VecInt.c:59:
if (VecLen(vec) > 0) {
i32 popped;
VecPopFront(vec, &popped);
}
break;- In
Vec.Remove.c:79:
// Test VecPopFront function
bool test_vec_pop_front(void) {
WriteFmtLn("Testing VecPopFront");
// Create a vector of integers
- In
Vec.Remove.c:97:
// Pop from the front
int popped;
VecPopFront(&vec, &popped);
// Check popped value
- In
Vec.Remove.c:111:
// Pop again
VecPopFront(&vec, &popped);
// Check popped value
- In
Remove.h:32:
/// TAGS: Str, Remove, Pop, Front
///
#define StrPopFront(str, chr) VecPopFront((str), (chr))
///
Last updated on