Skip to content

VecPushBackL

Description

Append a single element to the end of the vector. L-value ownership form.

Success

Returns true. The vector length grows by one; val occupies the new tail. When the vector has no copy_init handler, val has been zeroed (moved-from); otherwise unchanged.

Failure

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

Usage example (Cross-references)

Usage examples (Cross-references)
    
        // Add items to vectors
        VecPushBackL(&vec3, item4);
        VecPushBackL(&vec4, item5);
        // Add items to vectors
        VecPushBackL(&vec3, item4);
        VecPushBackL(&vec4, item5);
    
        // Check that item 4 and 5 are no longer valid
        // Test VecPushBackL
        int val1 = 10;
        VecPushBackL(&vec, val1);
    
        // Test VecPushFrontL
    // Test VecPushBackL zero-on-take behavior with complex structures
    bool test_lvalue_zero_on_take_pushback(void) {
        WriteFmt("Testing VecPushBackL zero-on-take with complex structures\n");
    
        // Create a test item
    
        // Insert with L-value semantics (vector takes ownership)
        VecPushBackL(&temp_vec, item);
    
        // Check that the item was zeroed
    
        // Add the dummy item using L-value semantics
        VecPushBackL(&vec, dummy);
    
        // Now insert our test item at position 0 using L-value semantics
    
        // Add the dummy items using L-value semantics
        VecPushBackL(&vec, dummy1);
        VecPushBackL(&vec, dummy2);
        VecPushBackL(&vec, dummy3);
        // Add the dummy items using L-value semantics
        VecPushBackL(&vec, dummy1);
        VecPushBackL(&vec, dummy2);
        VecPushBackL(&vec, dummy3);
        VecPushBackL(&vec, dummy1);
        VecPushBackL(&vec, dummy2);
        VecPushBackL(&vec, dummy3);
    
        // Test 1: Insert at the beginning
        ComplexItem dummy = {0};
        dummy.name        = ZstrDupAlloc("Dummy");
        VecPushBackL(&vec, dummy);
    
        // Insert with L-value semantics at the front (vector takes ownership)
    
        // Add items to vec2
        VecPushBackL(&vec2, item1);
        VecPushBackL(&vec2, item2);
        // Add items to vec2
        VecPushBackL(&vec2, item1);
        VecPushBackL(&vec2, item2);
    
        // Verify items were cleared after being added to vec2
        // Test L-value insert operations
        int l_value = 100;
        VecPushBackL(&vec, l_value);
    
        // Check that the element was added
        // Test VecPushBackL
        int val1 = 10;
        VecPushBackL(&vec, val1);
        bool result = (val1 == 0); // Should be zeroed
    #define VecMustPushBackL(v, val)                                                                                       \
        do {                                                                                                               \
            if (!VecPushBackL((v), (val))) {                                                                               \
                LOG_FATAL("VecMustPushBackL failed");                                                                      \
            }                                                                                                              \
    /// TAGS: Str, PushBack, Char, LValue
    ///
    #define StrPushBackL(str, lval) VecPushBackL((str), (lval))
    
    ///
Last updated on