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)

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

Share :

Related Posts

VecInitAlignedStack

VecInitAlignedStack Description Initialize given vector with given alignment. It is mandatory to initialize vectors before use. Not doing so is undefined behaviour. Provided alignment is used to keep all objects at an aligned memory location, avoiding UB in some cases. It’s recommended to use aligned vector when dealing with structs containing unions. These vectors are best used where user doesn’t get a chance to or does not want to deinit vector, given that no data in vector needs to be deinitialized. Example includes, but does not limit to a Vec(i8), Vec(f32), etc…

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

VecForeachPtr

VecForeachPtr Description Iterate over each element var of the given vector v (as a pointer). This is a convenience macro that iterates forward 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.

Read More