Skip to content

VecLast

Description

Last element of the vector by value. Caller must ensure the vector is non-empty.

Parameters

Name Direction Description
v in Vector to query.

Usage example (Cross-references)

Usage examples (Cross-references)
    
        while (VecLen(neighbors)) {
            GraphNodeId to = VecLast(neighbors);
            if (!graph_remove_edge_now(graph, from, to)) {
                LOG_FATAL("Graph failed to remove outgoing edge during node deletion");
            case VEC_CHAR_PTR_LAST : {
                if (VecLen(vec) > 0) {
                    char *last = VecLast(vec);
                    (void)last; // Use the result to avoid warnings
                }
            case VEC_STR_LAST : {
                if (VecLen(vec) > 0) {
                    Str last = VecLast(vec);
                    (void)last; // Use the result to avoid warnings
                }
            case VEC_INT_LAST : {
                if (VecLen(vec) > 0) {
                    volatile i32 last = VecLast(vec);
                    (void)last;
                }
    // Test VecFirst and VecLast functions
    bool test_vec_first_last(void) {
        WriteFmt("Testing VecFirst and VecLast\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        // Check first and last elements
        bool result = (VecFirst(&vec) == 10);
        result      = result && (VecLast(&vec) == 30);
    
        // Modify first and last elements
        // Modify first and last elements
        VecFirst(&vec) = 15;
        VecLast(&vec)  = 35;
    
        // Verify changes
    /// TAGS: Str, Access, Last
    ///
    #define StrLast(str) VecLast(str)
    
    ///
Last updated on