Skip to content

VecFirst

Description

First 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)
            case VEC_CHAR_PTR_FIRST : {
                if (VecLen(vec) > 0) {
                    char *first = VecFirst(vec);
                    (void)first; // Use the result to avoid warnings
                }
            case VEC_STR_FIRST : {
                if (VecLen(vec) > 0) {
                    Str first = VecFirst(vec);
                    (void)first; // Use the result to avoid warnings
                }
            case VEC_INT_FIRST : {
                if (VecLen(vec) > 0) {
                    volatile i32 first = VecFirst(vec);
                    (void)first;
                }
    // 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
        VecFirst(&vec) = 15;
        VecLast(&vec)  = 35;
    /// TAGS: Str, Access, First
    ///
    #define StrFirst(str) VecFirst(str)
    
    ///
Last updated on