Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-02-20 01:15:43 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-02-20 01:38:33 +0300
commitc1c01f062eddd084a122026c462f477299cf9d13 (patch)
tree473c1362448dd58c3f8bd0354c2e2580f88981e6 /source/blender/blenlib/BLI_listbase.h
parent0e7409d466f25f70674151b5fe62177104938729 (diff)
BLI_listbase: add an iterator macro that supports removal
Avoids manually defining 'for' loops that store the next item in the linked list.
Diffstat (limited to 'source/blender/blenlib/BLI_listbase.h')
-rw-r--r--source/blender/blenlib/BLI_listbase.h8
1 files changed, 7 insertions, 1 deletions
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
}