Skip to content

VecContains

Description

Check whether vector contains a matching element.

item_ptr must point to a value comparable with vector elements.

Parameters

Name Direction Description
v in Vector to search.
item_ptr in Pointer to searched value.
compare in Comparator returning 0 for equality.

Success

Returns true when at least one matching element exists. The vector is not modified.

Failure

Returns false when no element matches. The vector is not modified.

Usage example (Cross-references)

Usage examples (Cross-references)
    // Test VecEmpty, VecFind, and VecContains functions
    bool test_vec_empty_find_contains(void) {
        WriteFmt("Testing VecEmpty, VecFind, and VecContains\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        bool result  = VecEmpty(&vec);
        result       = result && (VecFind(&vec, &needle, compare_ints) == SIZE_MAX);
        result       = result && !VecContains(&vec, &needle, compare_ints);
    
        VecPushBackR(&vec, 10);
        result = result && !VecEmpty(&vec);
        result = result && (VecFind(&vec, &needle, compare_ints) == 1);
        result = result && VecContains(&vec, &needle, compare_ints);
        result = result && !VecContains(&vec, &missing, compare_ints);
        result = result && (VecFind(&vec, &missing, compare_ints) == SIZE_MAX);
        result = result && (VecFind(&vec, &needle, compare_ints) == 1);
        result = result && VecContains(&vec, &needle, compare_ints);
        result = result && !VecContains(&vec, &missing, compare_ints);
        result = result && (VecFind(&vec, &missing, compare_ints) == SIZE_MAX);
    /// TAGS: Str, Contains, Search, Compare
    ///
    #define StrContainsChar(str, chr_ptr, compare) VecContains((str), (chr_ptr), (compare))
    
    #ifdef __cplusplus
Last updated on