Introduce list_for_each utility for iterating over list_t

This commit is contained in:
Tudor Brindus 2020-06-19 17:55:07 -04:00
parent b3f08597cd
commit 2438a024df

View file

@ -27,6 +27,11 @@ void list_swap(list_t *list, int src, int dest);
// move item to end of list // move item to end of list
void list_move_to_end(list_t *list, void *item); void list_move_to_end(list_t *list, void *item);
#define list_for_each(e, list) \
for (__typeof__(e) *p = (__typeof__(e) *) (list)->items, (e) = *p; \
(void **) p < ((list)->items + (list)->length); \
p++, (e) = *p)
/* Calls `free` for each item in the list, then frees the list. /* Calls `free` for each item in the list, then frees the list.
* Do not use this to free lists of primitives or items that require more * Do not use this to free lists of primitives or items that require more
* complicated deallocation code. * complicated deallocation code.