Skip to content

VecPopFront

Description

Remove and optionally return the first element of the vector. Order of trailing elements is preserved.

Parameters

Name Direction Description
v in,out Vector handle.
ptr out Optional destination for the popped element. Pass NULL to just delete it (the configured copy_deinit is invoked instead).

Success

Returns to the caller. The vector length shrinks by one; all remaining elements have shifted left by one. When ptr is non-NULL the removed value is bit-copied into *ptr.

Failure

Function cannot fail. Calling on an empty vector is a caller bug and aborts via LOG_FATAL.

Usage example (Cross-references)

Usage examples (Cross-references)
                if (VecLen(vec) > 0) {
                    char *str;
                    VecPopFront(vec, &str);
                    // char_ptr_deinit is called automatically by the vector
                }
                if (VecLen(vec) > 0) {
                    Str str;
                    VecPopFront(vec, &str);
                    // StrDeinit is called automatically by the vector
                }
                if (VecLen(vec) > 0) {
                    i32 popped;
                    VecPopFront(vec, &popped);
                }
                break;
    // Test VecPopFront function
    bool test_vec_pop_front(void) {
        WriteFmtLn("Testing VecPopFront");
    
        // Create a vector of integers
        // Pop from the front
        int popped;
        VecPopFront(&vec, &popped);
    
        // Check popped value
    
        // Pop again
        VecPopFront(&vec, &popped);
    
        // Check popped value
    /// TAGS: Str, Remove, Pop, Front
    ///
    #define StrPopFront(str, chr) VecPopFront((str), (chr))
    
    ///
Last updated on