VecForeachInRange

Table of Contents

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.

Parameters

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

Usage example (Cross-references)

    if (start < end) {
    size_t total_len = 0;
    VecForeachInRange(vec, str, start, end) {
    total_len += strlen(str);
    }
    if (start < end) {
    size_t total_len = 0;
    VecForeachInRange(vec, str, start, end) {
    total_len += ZstrLen(str.data);
    }
    if (start < end) {
    int sum = 0;
    VecForeachInRange(vec, item, start, end) {
    sum += item;
    }
    /// end[in]      : Ending index (exclusive).
    ///
    #define StrForeachInRange(str, chr, start, end) VecForeachInRange((str), (chr), (start), (end))
    
    ///

Share :

Related Posts

IN_RANGE

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

Read More

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

VecForeachInRangeIdx

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

Read More