refactor(vector): add index to foreach

This commit is contained in:
2025-09-09 22:25:43 +02:00
parent 6b177c87c6
commit b2f7510d64
3 changed files with 5 additions and 5 deletions

View File

@@ -10,13 +10,13 @@ typedef struct my_elem {
} my_elem_s;
/* Functions used to iterate for each vector's element */
static void multiply(void *elem) {
static void multiply(size_t index, void *elem) {
my_elem_s *e = (my_elem_s *)elem;
e->age = e->age * 2;
}
/* Another way to use foreach
static void print(void *elem) {
static void print(size_t index, void *elem) {
my_elem_s *e = (my_elem_s *)elem;
printf("%s (%d)\n", e->name, e->age);
}