Skip to content
VecPushBackArrR

VecPushBackArrR

Description

Append a contiguous range of elements to the end of the vector. R-value form.

Success

Returns true. The vector length grows by count; copies of the source elements occupy [old_length, new_length). 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);
                    }
                    VecPushBackArrR(vec, values, count);
                }
                break;
    
        // Clone the source vector into the destination
        VecPushBackArrR(&clone, VecBegin(&src), VecLen(&src));
    
        // Check that the clone has the same data but different memory
        // Add some initial elements
        int values[] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
        VecPushBackArrR(&vec, values, 9);
    
        // Test VecDelete (regular delete)
    
        // Add elements again
        VecPushBackArrR(&vec, values, 9);
    
        // Test VecDeleteFast (fast delete)
    
        // Add elements again
        VecPushBackArrR(&vec, values, 9);
    
        // Create an L-value index to use with regular VecDelete
        // Create a small array and use count=0
        int small_arr[1] = {42};
        VecPushBackArrR(&vec, small_arr, 0);
        result = result && (VecLen(&vec) == 1); // Length should not change
        // Push an array to the back
        int values[] = {10, 20, 30, 40, 50};
        VecPushBackArrR(&vec, values, 5);
    
        // Check length
        // Push another array to the back
        int more_values[] = {60, 70, 80};
        VecPushBackArrR(&vec, more_values, 3);
    
        // Check length
        // Add some initial elements
        int initial[] = {10, 20, 30};
        VecPushBackArrR(&vec, initial, 3);
    
        // Create another vector with elements to insert
        IntVec src          = VecInit(&alloc);
        int    src_values[] = {40, 50, 60};
        VecPushBackArrR(&src, src_values, 3);
    
        // Insert range in the middle
        // Add some elements to first vector
        int values1[] = {10, 20, 30};
        VecPushBackArrR(&vec1, values1, 3);
    
        // Create second vector
        // Add some elements to second vector
        int values2[] = {40, 50, 60};
        VecPushBackArrR(&vec2, values2, 3);
    
        // Merge vec2 into vec1
        IntVec src      = VecInit(&local_heap);
        int    values[] = {10, 20, 30};
        VecPushBackArrR(&src, values, 3);
    
        // Build dst on the SAME allocator as src, then clone the data.
        dst.copy_init   = src.copy_init;
        dst.copy_deinit = src.copy_deinit;
        bool cloned     = VecPushBackArrR(&dst, VecBegin(&src), VecLen(&src));
    
        bool allocator_matches = VecAllocator(&dst) == VecAllocator(&src);
    
        // R-value array operations
        VecPushBackArrR(&vec, arr, 3);
    
        // Check that the elements were added
    #define VecMustPushBackArrR(v, arr, count)                                                                             \
        do {                                                                                                               \
            if (!VecPushBackArrR((v), (arr), (count))) {                                                                   \
                LOG_FATAL("VecMustPushBackArrR failed");                                                                   \
            }                                                                                                              \
    #define StrPushBackMany(...) OVERLOAD(StrPushBackMany, __VA_ARGS__)
    #define StrPushBackMany_2(str, zstr)                                                                               \
        _Generic((zstr), Zstr: VecPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrPushBackMany_3(str, cstr, cstr_len)                                                                     \
        _Generic((cstr), Zstr: VecPushBackArrR((str), (Zstr)(cstr), (cstr_len)), char *: VecPushBackArrR((str), (Zstr)(cstr), (cstr_len)))
        _Generic((zstr), Zstr: VecPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrPushBackMany_3(str, cstr, cstr_len)                                                                     \
        _Generic((cstr), Zstr: VecPushBackArrR((str), (Zstr)(cstr), (cstr_len)), char *: VecPushBackArrR((str), (Zstr)(cstr), (cstr_len)))
    
    ///
    /// TAGS: Str, PushBack, Range, RValue
    ///
    #define StrPushBackArrR(str, arr, count) VecPushBackArrR((str), (arr), (count))
    
    ///
Last updated on