VecForeachPtrInRange

Table of Contents

VecForeachPtrInRange

Description

Iterate over elements in a specific range of the given vector v (as pointers). This is a convenience macro that iterates over a range using an internally managed index and provides a pointer to each element. The variable var is declared and defined by this macro as a pointer to the vector’s data type.

Parameters

NameDirectionDescription
vin,outVector to iterate over.
varinName of pointer variable to be used which’ll point to the current element.
startinStarting index (inclusive).
endinEnding index (exclusive).

Usage example (Cross-references)

    /// end[in]      : Ending index (exclusive).
    ///
    #define StrForeachPtrInRange(str, chrptr, start, end) VecForeachPtrInRange((str), (chrptr), (start), (end))
    
    #ifdef __cplusplus
    if (start < end) {
    int sum = 0;
    VecForeachPtrInRange(vec, item_ptr, start, end) {
    sum += *item_ptr;
    }
    if (start < end) {
    size_t total_len = 0;
    VecForeachPtrInRange(vec, str_ptr, start, end) {
    total_len += ZstrLen(str_ptr->data);
    }
    if (start < end) {
    size_t total_len = 0;
    VecForeachPtrInRange(vec, str_ptr, start, end) {
    total_len += strlen(*str_ptr);
    }

Share :

Related Posts

VecForeachReverseIdx

VecForeachReverseIdx Description Iterate over each element var of given vector v at each index idx into the vector. The variables var and idx declared and defined by this macro. idx will start from v->length - 1 and will go till 0

Read More

VecForeachReverse

VecForeachReverse Description Iterate over each element var of the given vector v in reverse order. This is a convenience macro that iterates backward using an internally managed index. The variable var is declared and defined by this macro.

Read More

VecForeachInRange

VecForeachInRange Description Iterate over elements in a specific range of the given vector v. This is a convenience macro that iterates over a range using an internally managed index. The variable var is declared and defined by this macro.

Read More