Skip to content
VecInsertRangeR

VecInsertRangeR

Description

Insert a contiguous range of elements at the given index, preserving order. R-value form: the source range is treated as read-only input and is not zeroed.

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.

Success

Returns true. The vector length grows by count; copies of the source elements now occupy indices [idx, idx + count); previous elements at and after idx have shifted right by count. The source range is untouched.

Failure

Returns false on allocation failure. The vector is unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
                        values[i] = (i32)extract_u32(data, offset, data_size);
                    }
                    VecInsertRangeR(vec, values, idx, count);
                }
                break;
        // Push an array at a specific index
        int values[] = {30, 40, 50};
        VecInsertRangeR(&vec, values, 1, 3);
    
        // Check length
    
        // Insert range in the middle
        VecInsertRangeR(&vec, VecBegin(&src), 1, VecLen(&src));
    
        // Check length
    /// TAGS: Vec, PushBack, Range, RValue
    ///
    #define VecPushBackArrR(v, arr, count) VecInsertRangeR((v), (arr), (v)->length, (count))
    
    ///
    /// TAGS: Vec, PushFront, Range, RValue
    ///
    #define VecPushFrontArrR(v, arr, count) VecInsertRangeR((v), (arr), 0, (count))
    
    ///
    #define VecMustInsertRangeR(v, varr, idx, count)                                                                       \
        do {                                                                                                               \
            if (!VecInsertRangeR((v), (varr), (idx), (count))) {                                                           \
                LOG_FATAL("VecMustInsertRangeR failed");                                                                   \
            }                                                                                                              \
    #define StrInsertMany(...) OVERLOAD(StrInsertMany, __VA_ARGS__)
    #define StrInsertMany_3(str, zstr, idx)                                                                            \
        _Generic((zstr), Zstr: VecInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrInsertMany_4(str, cstr, cstr_len, idx)                                                                  \
        _Generic((cstr), Zstr: VecInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)))
        _Generic((zstr), Zstr: VecInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrInsertMany_4(str, cstr, cstr_len, idx)                                                                  \
        _Generic((cstr), Zstr: VecInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)))
    
    ///
    /// TAGS: Str, Insert, Range, RValue
    ///
    #define StrInsertRangeR(str, varr, idx, count) VecInsertRangeR((str), (varr), (idx), (count))
    
    ///
Last updated on