VecForeachInRangeIdx

Table of Contents

VecForeachInRangeIdx

Description

Iterate over elements in a specific range of the given vector v at each index idx. The variables var and idx are declared and defined by this macro. idx will start from start and will go till end - 1

Parameters

NameDirectionDescription
vin,outVector to iterate over.
varinName of variable to be used which’ll contain value at iterated index idx.
idxinName of variable to be used for iterating over indices.
startinStarting index (inclusive).
endinEnding index (exclusive).

Usage example (Cross-references)

    if (start < end) {
    size_t total_len = 0;
    VecForeachInRangeIdx(vec, str, idx, start, end) {
    total_len += strlen(str) + idx;
    }
    if (start < end) {
    size_t total_len = 0;
    VecForeachInRangeIdx(vec, str, idx, start, end) {
    total_len += ZstrLen(str.data) + idx;
    }
    if (start < end) {
    int sum = 0;
    VecForeachInRangeIdx(vec, item, idx, start, end) {
    sum += item + (int)idx;
    }
    /// TAGS: Foreach, Vec, Iteration, Loop, Range
    ///
    #define VecForeachInRange(v, var, start, end) VecForeachInRangeIdx((v), (var), (____iter___), (start), (end))
    
    ///
    /// end[in]      : Ending index (exclusive).
    ///
    #define StrForeachInRangeIdx(str, chr, idx, start, end) VecForeachInRangeIdx((str), (chr), idx, (start), (end))
    
    ///

Share :

Related Posts

IN_RANGE

IN_RANGE Description Checks if the value x is within the inclusive range [lo, hi].

Read More

VecForeachPtrIdx

VecForeachPtrIdx 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 0 and will go till v->length - 1

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