VecPopBack

Table of Contents

VecPopBack

Description

Pop item from vector back.

Parameters

NameDirectionDescription
vin,outVector to pop item from.
ptroutPopped item will be stored here. Make sure this has sufficient memory to store memcopied data. If no pointer is provided, then it’s equivalent to deleting item from last position.

Success

return

Failure

Does not return

Usage example (Cross-references)

    // Test VecPopBack function
    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
    /// FAILURE : Does not return
    ///
    #define VecDeleteLast(v) VecPopBack((v), (VEC_DATATYPE(v) *)NULL)
    
    ///
    /// FAILURE : Returns NULL otherwise.
    ///
    #define StrPopBack(str, chr) VecPopBack((str), (chr))
    
    ///
    if (VecLen(vec) > 0) {
    i32 popped;
    VecPopBack(vec, &popped);
    }
    break;
    if (VecLen(vec) > 0) {
    Str str;
    VecPopBack(vec, &str);
    // StrDeinit is called automatically by the vector
    }
    if (VecLen(vec) > 0) {
    char *str;
    VecPopBack(vec, &str);
    // char_ptr_deinit is called automatically by the vector
    }

Share :