Skip to content
VecInsertRangeL

VecInsertRangeL

Description

Insert a contiguous range of elements at the given index, preserving order. L-value form: takes ownership of the source range on success when the vector has no copy_init handler (source bytes are zeroed). On failure the source is left untouched.

Parameters

Name Direction Description
v in,out Vector handle.
varr in Pointer to the source array. Must be non-NULL when count > 0.
idx in Position in [0, length].
count in Number of elements to insert.

Usage example (from documentation)

  int items[] = { 1, 2, 3 };
  if (!VecInsertRangeL(&v, items, 0, 3)) { /* recover */ }

Success

Returns true. The vector length grows by count. Source bytes now occupy indices [idx, idx + count); previous elements at and after idx have shifted right by count. When the vector has no copy_init handler, the count * sizeof(element) source bytes have been zeroed.

Failure

Returns false on allocation failure. Both vector and source are unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
        // Test VecInsertRangeL
        int range[] = {80, 90, 100};
        VecInsertRangeL(&vec, range, 1, 3);
    
        // Check that array elements are zeroed
    /// TAGS: Vec, Insert, Range
    ///
    #define VecInsertRange(v, varr, idx, count) VecInsertRangeL((v), (varr), (idx), (count))
    
    ///
    /// TAGS: Vec, PushBack, Range, LValue
    ///
    #define VecPushBackArrL(v, arr, count) VecInsertRangeL((v), (arr), (v)->length, (count))
    
    ///
    /// TAGS: Vec, PushFront, Range, LValue
    ///
    #define VecPushFrontArrL(v, arr, count) VecInsertRangeL((v), (arr), 0, (count))
    
    ///
    #define VecMustInsertRangeL(v, varr, idx, count)                                                                       \
        do {                                                                                                               \
            if (!VecInsertRangeL((v), (varr), (idx), (count))) {                                                           \
                LOG_FATAL("VecMustInsertRangeL failed");                                                                   \
            }                                                                                                              \
    /// TAGS: Str, Insert, Range, LValue
    ///
    #define StrInsertRangeL(str, varr, idx, count) VecInsertRangeL((str), (varr), (idx), (count))
    
    ///
Last updated on