Skip to content

VecPushBack

Description

Append a single element to the end of the vector, taking ownership of val when no deep-copy handler is configured. Default unsuffixed form aliasing to the L (ownership) variant; expands through VecInsert at index length. See VecPushBackL for the full SUCCESS/FAILURE contract.

Usage example (Cross-references)

Usage examples (Cross-references)
        sp.target     = target.target;
        sp.seen       = false;
        VecPushBack(&self->specs, sp);
    }
            help.kind       = ARG_KIND_BOOL;
            help.target     = NULL;
            VecPushBack(&self->specs, help);
        }
                entry.free_trace_n = (u32)CaptureStackTrace(entry.free_trace, depth, 3);
            }
            VecPushBack(&self->freed, entry);
        }
            if (next) {
                StrIter si = {.data = (char *)prev, .length = next - prev, .pos = 0, .alignment = 1};
                VecPushBack(&sv, si);
                prev = next + keylen;
            } else {
            } else {
                StrIter si = {.data = (char *)prev, .length = end - prev, .pos = 0, .alignment = 1};
                VecPushBack(&sv, si);
                break;
            }
                if (next) {
                    Str tmp = StrInitFromCstr(prev, next - prev, s->allocator);
                    VecPushBack(&sv, tmp);
                    prev = next + keylen;
                } else {
                    if (ZstrCompareN(prev, key, end - prev)) {
                        Str tmp = StrInitFromCstr(prev, end - prev, s->allocator);
                        VecPushBack(&sv, tmp);
                    }
                    break;
    
                direntry.name = StrInitFromCstr(findFileData.cFileName, ZstrLen(findFileData.cFileName), alloc);
                VecPushBack(&dc, direntry);
            } while (FindNextFile(hFind, &findFileData) != 0);
        }
                    direntry.type     = dirent_type_to_misra(de->d_type);
                    direntry.name     = StrInitFromCstr(nm, name_len, alloc);
                    VecPushBack(&dc, direntry);
                }
                off += de->d_reclen;
                char *str = generate_cstring(data, offset, data_size, 32);
                if (str) {
                    VecPushBack(vec, str);
                    cleanup_cstring(str);
                }
                        char *str = generate_cstring(data, offset, data_size, 16);
                        if (str) {
                            VecPushBack(&temp, str);
                            cleanup_cstring(str);
                        }
                        char *str = generate_cstring(data, offset, data_size, 16);
                        if (str) {
                            VecPushBack(&temp, str);
                            cleanup_cstring(str);
                        }
            case VEC_STR_PUSH_BACK : {
                Str str = generate_str_from_input(data, offset, data_size, 32, alloc);
                VecPushBack(vec, str);
                break;
            }
                    for (size_t i = 0; i < count; i++) {
                        Str str = generate_str_from_input(data, offset, data_size, 16, alloc);
                        VecPushBack(&temp, str);
                    }
                    for (size_t i = 0; i < count; i++) {
                        Str str = generate_str_from_input(data, offset, data_size, 16, alloc);
                        VecPushBack(&temp, str);
                        StrDeinit(&str);
                    }
            case VEC_INT_PUSH_BACK : {
                i32 value = (i32)extract_u32(data, offset, data_size);
                VecPushBack(vec, value);
                break;
            }
                for (uint8_t i = 0; i < count && *offset + 4 <= data_size; i++) {
                    i32 value = (i32)extract_u32(data, offset, data_size);
                    VecPushBack(&temp, value);
                }
                for (uint8_t i = 0; i < count && *offset + 4 <= data_size; i++) {
                    i32 value = (i32)extract_u32(data, offset, data_size);
                    VecPushBack(&temp, value);
                }
                i32 value = 0;
                JR_INT(si1, value);
                VecPushBack(&items, value);
            });
        });
                Str value = StrInit(&alloc);
                JR_STR(si2, value);
                VecPushBack(&data, value);
            });
        });
                i32 item = 0;
                JR_INT(si, item);
                VecPushBack(&obj.filled_items, item);
            });
        });
        sym.binary_id             = 888;
        sym.debug                 = true;
        VecPushBack(&response.data, sym);
    
        JW_OBJ(json, {
        FunctionInfo func1 = {12345, StrInitFromZstr("test_func", &alloc), 1024, 4096};
        FunctionInfo func2 = {54321, StrInitFromZstr("helper_func", &alloc), 512, 8192};
        VecPushBack(&functions, func1);
        VecPushBack(&functions, func2);
        FunctionInfo func2 = {54321, StrInitFromZstr("helper_func", &alloc), 512, 8192};
        VecPushBack(&functions, func1);
        VecPushBack(&functions, func2);
    
        JW_OBJ(json, {
        Str tag2 = StrInitFromZstr("x86", &alloc);
    
        VecPushBack(&result.tags, tag1);
        VecPushBack(&result.tags, tag2);
    
        VecPushBack(&result.tags, tag1);
        VecPushBack(&result.tags, tag2);
    
        result.created_at = StrInitFromZstr("2024-04-01", &alloc);
        sym1.target_function_id    = 222;
        sym1.distance              = 0.9;
        VecPushBack(&symbols, sym1);
    
        AnnSymbol sym2             = {0};
        sym2.target_function_id    = 444;
        sym2.distance              = 0.8;
        VecPushBack(&symbols, sym2);
    
        JW_OBJ(json, {
        Vec(u32) numbers = VecInit(&alloc);
        u32 num1 = 1, num2 = 2, num3 = 3;
        VecPushBack(&numbers, num1);
        VecPushBack(&numbers, num2);
        VecPushBack(&numbers, num3);
        u32 num1 = 1, num2 = 2, num3 = 3;
        VecPushBack(&numbers, num1);
        VecPushBack(&numbers, num2);
        VecPushBack(&numbers, num3);
        VecPushBack(&numbers, num1);
        VecPushBack(&numbers, num2);
        VecPushBack(&numbers, num3);
    
        Vec(Str) strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
        Str str3 = StrInitFromZstr("c", &alloc);
    
        VecPushBack(&strings, str1);
        VecPushBack(&strings, str2);
        VecPushBack(&strings, str3);
    
        VecPushBack(&strings, str1);
        VecPushBack(&strings, str2);
        VecPushBack(&strings, str3);
        VecPushBack(&strings, str1);
        VecPushBack(&strings, str2);
        VecPushBack(&strings, str3);
    
        Vec(bool) booleans = VecInit(&alloc);
        Vec(bool) booleans = VecInit(&alloc);
        bool bool1 = true, bool2 = false, bool3 = true;
        VecPushBack(&booleans, bool1);
        VecPushBack(&booleans, bool2);
        VecPushBack(&booleans, bool3);
        bool bool1 = true, bool2 = false, bool3 = true;
        VecPushBack(&booleans, bool1);
        VecPushBack(&booleans, bool2);
        VecPushBack(&booleans, bool3);
        VecPushBack(&booleans, bool1);
        VecPushBack(&booleans, bool2);
        VecPushBack(&booleans, bool3);
    
        JW_OBJ(json, {
        Str lang3 = StrInitFromZstr("Rust", &alloc);
    
        VecPushBack(&languages, lang1);
        VecPushBack(&languages, lang2);
        VecPushBack(&languages, lang3);
    
        VecPushBack(&languages, lang1);
        VecPushBack(&languages, lang2);
        VecPushBack(&languages, lang3);
        VecPushBack(&languages, lang1);
        VecPushBack(&languages, lang2);
        VecPushBack(&languages, lang3);
    
        JW_OBJ(json, { JW_ARR_KV(json, "languages", languages, lang, { JW_STR(json, lang); }); });
        Str tag3 = StrInitFromZstr("portable", &alloc);
    
        VecPushBack(&product.tags, tag1);
        VecPushBack(&product.tags, tag2);
        VecPushBack(&product.tags, tag3);
    
        VecPushBack(&product.tags, tag1);
        VecPushBack(&product.tags, tag2);
        VecPushBack(&product.tags, tag3);
        VecPushBack(&product.tags, tag1);
        VecPushBack(&product.tags, tag2);
        VecPushBack(&product.tags, tag3);
    
        JW_OBJ(json, {
        Vec(i32) filled_arr = VecInit(&alloc);
        i32 val1 = 1, val2 = 2;
        VecPushBack(&filled_arr, val1);
        VecPushBack(&filled_arr, val2);
        i32 val1 = 1, val2 = 2;
        VecPushBack(&filled_arr, val1);
        VecPushBack(&filled_arr, val2);
    
        i32 x_value = 1;
                    });
    
                    VecPushBack(&symbols, sym);
                });
            });
                        });
    
                        VecPushBack(&response.data, sym);
                    });
                });
                        );
    
                        VecPushBack(&response.data, sym);
                        WriteFmt("[DEBUG] Added symbol to vector, length now: {}\n", VecLen(&response.data));
                    });
                        );
    
                        VecPushBack(&response.data, sym);
                        WriteFmt("[DEBUG] Added symbol to vector, length now: {}\n", VecLen(&response.data));
                    });
                Str lang = StrInit(&alloc);
                JR_STR(si, lang);
                VecPushBack(&languages, lang);
            });
        });
                Str tag = StrInit(&alloc);
                JR_STR(si, tag);
                VecPushBack(&product.tags, tag);
            });
        });
        i32 nums[5] = {1, 2, 3, -5, 0};
        for (size i = 0; i < 5; i++) {
            VecPushBack(&original_numbers, nums[i]);
        }
        Str str4 = StrInitFromZstr("last", &alloc);
    
        VecPushBack(&original_strings, str1);
        VecPushBack(&original_strings, str2);
        VecPushBack(&original_strings, str3);
    
        VecPushBack(&original_strings, str1);
        VecPushBack(&original_strings, str2);
        VecPushBack(&original_strings, str3);
        VecPushBack(&original_strings, str4);
        VecPushBack(&original_strings, str1);
        VecPushBack(&original_strings, str2);
        VecPushBack(&original_strings, str3);
        VecPushBack(&original_strings, str4);
        VecPushBack(&original_strings, str2);
        VecPushBack(&original_strings, str3);
        VecPushBack(&original_strings, str4);
    
        // Write to JSON
                i32 num = 0;
                JR_INT(si, num);
                VecPushBack(&parsed_numbers, num);
            });
            JR_ARR_KV(si, "strings", {
                Str str = StrInit(&alloc);
                JR_STR(si, str);
                VecPushBack(&parsed_strings, str);
            });
        });
        Str feature2 = StrInitFromZstr("logging", &alloc);
    
        VecPushBack(&original.config.features, feature1);
        VecPushBack(&original.config.features, feature2);
    
        VecPushBack(&original.config.features, feature1);
        VecPushBack(&original.config.features, feature2);
    
        original.numbers = VecInitT(original.numbers, &alloc);
        i32 vals[3]      = {10, 20, -5};
        for (size i = 0; i < 3; i++) {
            VecPushBack(&original.numbers, vals[i]);
        }
        bool bools[3]  = {true, false, true};
        for (size i = 0; i < 3; i++) {
            VecPushBack(&original.flags, bools[i]);
        }
                    Str feature = StrInit(&alloc);
                    JR_STR(si, feature);
                    VecPushBack(&parsed.config.features, feature);
                });
            });
                i32 num = 0;
                JR_INT(si, num);
                VecPushBack(&parsed.numbers, num);
            });
            JR_ARR_KV(si, "flags", {
                bool flag = false;
                JR_BOOL(si, flag);
                VecPushBack(&parsed.flags, flag);
            });
        });
                i32 num = 0;
                JR_INT(si, num);
                VecPushBack(&parsed_numbers, num);
            });
            JR_ARR_KV(si, "empty_strings", {
                Str str = StrInit(&alloc);
                JR_STR(si, str);
                VecPushBack(&parsed_strings, str);
            });
            JR_OBJ_KV(si, "empty_object", { found_empty_object = true; });
        for (int i = 0; i < 5; i++) {
            int val = values[i];
            VecPushBack(&vec, val);
        }
        for (int i = 0; i < 5; i++) {
            int val = values[i];
            VecPushBack(&vec, val);
        }
        for (int i = 0; i < 5; i++) {
            int val = values[i];
            VecPushBack(&vec, val);
        }
        for (int i = 0; i < 5; i++) {
            int val = values[i];
            VecPushBack(&vec, val);
        }
        for (int i = 0; i < 7; i++) {
            int val = values[i];
            VecPushBack(&vec, val);
        }
        for (int i = 0; i < 10; i++) {
            int val = i * 10;
            VecPushBack(&vec, val);
        }
        for (int i = 0; i < 5; i++) {
            int val = values[i];
            VecPushBack(&vec, val);
        }
        int values[] = {10, 20, 30, 40, 50};
        for (int i = 0; i < 5; i++) {
            VecPushBack(&vec, values[i]);
        }
        int values[] = {10, 20, 30, 40, 50};
        for (int i = 0; i < 5; i++) {
            VecPushBack(&vec, values[i]);
        }
        int values[] = {10, 20, 30, 40, 50};
        for (int i = 0; i < 5; i++) {
            VecPushBack(&vec, values[i]);
        }
        int values[] = {10, 20, 30, 40, 50};
        for (int i = 0; i < 5; i++) {
            VecPushBack(&vec, values[i]);
        }
        int values[] = {10, 20, 30, 40, 50, 60, 70};
        for (int i = 0; i < 7; i++) {
            VecPushBack(&vec, values[i]);
        }
        int values[] = {10, 20, 30, 40, 50, 60, 70};
        for (int i = 0; i < 7; i++) {
            VecPushBack(&vec, values[i]);
        }
        int values[] = {10, 20, 30, 40, 50, 60, 70};
        for (int i = 0; i < 7; i++) {
            VecPushBack(&vec, values[i]);
        }
        int values[] = {10, 20, 30, 40, 50, 60, 70};
        for (int i = 0; i < 7; i++) {
            VecPushBack(&vec, values[i]);
        }
        Str s2 = StrInitFromZstr("World", &alloc);
    
        VecPushBack(&sv, s1);
        VecPushBack(&sv, s2);
    
        VecPushBack(&sv, s1);
        VecPushBack(&sv, s2);
    
        // Check that it behaves like a Vec of Str objects
    
    bool test_vec_push_back(void) {
        WriteFmt("Testing VecPushBack\n");
    
        // Create a vector of integers
    #define VecMustPushBack(v, val)                                                                                        \
        do {                                                                                                               \
            if (!VecPushBack((v), (val))) {                                                                                \
                LOG_FATAL("VecMustPushBack failed");                                                                       \
            }                                                                                                              \
Last updated on