Skip to content

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)
                    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
                }
                    size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
                    Str    str;
                    VecRemove(vec, &str, index);
                    // StrDeinit is called automatically by the vector
                }
                if (idx < VecLen(vec)) {
                    i32 removed;
                    VecRemove(vec, &removed, idx);
                }
                break;
    /// TAGS: Vec, Remove, Pop, Back
    ///
    #define VecPopBack(v, ptr) VecRemove((v), (ptr), (v)->length - 1)
    
    ///
    /// TAGS: Vec, Remove, Pop, Front
    ///
    #define VecPopFront(v, ptr) VecRemove((v), (ptr), 0)
    
    ///
    /// TAGS: Vec, Delete
    ///
    #define VecDelete(v, idx) VecRemove((v), (VEC_DATATYPE(v) *)NULL, (idx))
    
    ///
    /// TAGS: Str, Remove, Char
    ///
    #define StrRemove(str, chr, idx) VecRemove((str), (chr), (idx))
    
    ///
Last updated on