VecForeachPtrInRange
- Macro
- October 8, 2025
Table of Contents
VecForeachPtrInRange
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
Name | Direction | Description |
---|---|---|
v | in,out | Vector to iterate over. |
var | in | Name of pointer variable to be used which’ll point to the current element. |
start | in | Starting index (inclusive). |
end | in | Ending index (exclusive). |
Usage example (Cross-references)
- In
Foreach.h:172
:
/// end[in] : Ending index (exclusive).
///
#define StrForeachPtrInRange(str, chrptr, start, end) VecForeachPtrInRange((str), (chrptr), (start), (end))
#ifdef __cplusplus
- In
VecInt.c:520
:
if (start < end) {
int sum = 0;
VecForeachPtrInRange(vec, item_ptr, start, end) {
sum += *item_ptr;
}
- In
VecStr.c:550
:
if (start < end) {
size_t total_len = 0;
VecForeachPtrInRange(vec, str_ptr, start, end) {
total_len += ZstrLen(str_ptr->data);
}
- In
VecCharPtr.c:588
:
if (start < end) {
size_t total_len = 0;
VecForeachPtrInRange(vec, str_ptr, start, end) {
total_len += strlen(*str_ptr);
}