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)

    /// 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))
    
    ///
    if (start < end) {
    int sum = 0;
    VecForeachInRangeIdx(vec, item, idx, start, end) {
    sum += item + (int)idx;
    }
    if (start < end) {
    size_t total_len = 0;
    VecForeachInRangeIdx(vec, str, idx, start, end) {
    total_len += ZstrLen(str.data) + idx;
    }
    if (start < end) {
    size_t total_len = 0;
    VecForeachInRangeIdx(vec, str, idx, start, end) {
    total_len += strlen(str) + idx;
    }

Share :

Related Posts

VecForeachPtrReverseIdx

VecForeachPtrReverseIdx 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

VecForeach

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

Read More

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