Skip to content

VecPopBack

Description

Remove and optionally return the last element of the vector.

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. 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)
        }
    
        VecPopBack(&graph->free_indices, &index);
        return index;
    }
                if (VecLen(vec) > 0) {
                    char *str;
                    VecPopBack(vec, &str);
                    // char_ptr_deinit is called automatically by the vector
                }
                if (VecLen(vec) > 0) {
                    Str str;
                    VecPopBack(vec, &str);
                    // StrDeinit is called automatically by the vector
                }
                if (VecLen(vec) > 0) {
                    i32 popped;
                    VecPopBack(vec, &popped);
                }
                break;
    
    bool test_vec_pop_back(void) {
        WriteFmtLn("Testing VecPopBack");
    
        // Create a vector of integers
        // Pop from the back
        int popped;
        VecPopBack(&vec, &popped);
    
        // Check popped value
    
        // Pop again
        VecPopBack(&vec, &popped);
    
        // Check popped value
    /// TAGS: Vec, Delete, Back
    ///
    #define VecDeleteLast(v) VecPopBack((v), (VEC_DATATYPE(v) *)NULL)
    
    ///
    /// TAGS: Str, Remove, Pop, Back
    ///
    #define StrPopBack(str, chr) VecPopBack((str), (chr))
    
    ///
Last updated on