[Bf-blender-cvs] [c1c01f062ed] master: BLI_listbase: add an iterator macro that supports removal

Campbell Barton noreply at git.blender.org
Tue Feb 19 23:39:25 CET 2019


Commit: c1c01f062eddd084a122026c462f477299cf9d13
Author: Campbell Barton
Date:   Wed Feb 20 09:15:43 2019 +1100
Branches: master
https://developer.blender.org/rBc1c01f062eddd084a122026c462f477299cf9d13

BLI_listbase: add an iterator macro that supports removal

Avoids manually defining 'for' loops that store the next item in the
linked list.

===================================================================

M	source/blender/blenlib/BLI_listbase.h

===================================================================

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
 }



More information about the Bf-blender-cvs mailing list