Skip to content

VecPushFrontL

Description

Prepend a single element at the front of the vector. L-value ownership form.

Success

Returns true. The vector length grows by one; val occupies index 0; previous elements have shifted right by one. 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)
        // Test VecPushFrontL
        int val2 = 20;
        VecPushFrontL(&vec, val2);
    
        // Test VecInsertL
    // Test VecPushFrontL zero-on-take behavior with complex structures
    bool test_lvalue_zero_on_take_pushfront(void) {
        WriteFmt("Testing VecPushFrontL zero-on-take with complex structures\n");
    
        // Create a test item
    
        // Insert with L-value semantics at the front (vector takes ownership)
        VecPushFrontL(&vec, item);
    
        // Check that the item was zeroed
        // Test VecPushFrontL
        int val2 = 20;
        VecPushFrontL(&vec, val2);
        result = result && (val2 == 0); // Should be zeroed
    /// TAGS: Vec, PushFront, Insert
    ///
    #define VecPushFront(v, val) VecPushFrontL((v), (val))
    
    ///
    #define VecMustPushFrontL(v, val)                                                                                      \
        do {                                                                                                               \
            if (!VecPushFrontL((v), (val))) {                                                                              \
                LOG_FATAL("VecMustPushFrontL failed");                                                                     \
            }                                                                                                              \
    /// TAGS: Str, PushFront, Char, LValue
    ///
    #define StrPushFrontL(str, lval) VecPushFrontL((str), (lval))
    
    ///
Last updated on