From c1c01f062eddd084a122026c462f477299cf9d13 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 20 Feb 2019 09:15:43 +1100 Subject: BLI_listbase: add an iterator macro that supports removal Avoids manually defining 'for' loops that store the next item in the linked list. --- source/blender/blenlib/BLI_listbase.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index 85be4405d6c..cb0d394bd0b 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -125,7 +125,13 @@ if ((lb)->last && (lb_init || (lb_init = (lb)->last))) { \ #define LISTBASE_FOREACH(type, var, list) \ for (type var = (type)((list)->first); \ var != NULL; \ - var = (type)(((Link*)(var))->next)) + var = (type)(((Link *)(var))->next)) + +/** A verion of #LISTBASE_FOREACH that supports removing the item we're looping over. */ +#define LISTBASE_FOREACH_MUTABLE(type, var, list) \ + for (type var = (type)((list)->first), *var##_iter_next; \ + ((var != NULL) ? ((void)(var##_iter_next = (type)(((Link *)(var))->next)), 1) : 0); \ + var = var##_iter_next) #ifdef __cplusplus } -- cgit v1.2.3