Commit: 762e4cf221afa6edf6155c302e3839012b169abe
Author: Campbell Barton
Date:   Wed Aug 19 13:36:57 2020 +1000
Branches: blender-v2.90-release
https://developer.blender.org/rB762e4cf221afa6edf6155c302e3839012b169abe

BLI_listbase: add utility macro for looping over lists with an index

Add to the 2.90 branch to avoid problems if fixes from master use it.

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

M       .clang-format
M       source/blender/blenlib/BLI_listbase.h

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

diff --git a/.clang-format b/.clang-format
index cb5cdab496f..77b90dc68f9 100644
--- a/.clang-format
+++ b/.clang-format
@@ -236,6 +236,7 @@ ForEachMacros:
   - LISTBASE_CIRCULAR_FORWARD_BEGIN
   - LISTBASE_FOREACH
   - LISTBASE_FOREACH_BACKWARD
+  - LISTBASE_FOREACH_INDEX
   - LISTBASE_FOREACH_MUTABLE
   - LISTBASE_FOREACH_BACKWARD_MUTABLE
   - MAN_ITER_AXES_BEGIN
diff --git a/source/blender/blenlib/BLI_listbase.h 
b/source/blender/blenlib/BLI_listbase.h
index fa7cf7a1847..932b63e43f7 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -186,6 +186,14 @@ struct LinkData *BLI_genericNodeN(void *data);
        ((var != NULL) ? ((void)(var##_iter_prev = (type)(((Link 
*)(var))->prev)), 1) : 0); \
        var = var##_iter_prev)
 
+/**
+ * A version of #LISTBASE_FOREACH that takes an index variable (declared 
outside this macro).
+ * This avoids possible accidents where using `continue` could miss 
incrementing the counter.
+ */
+#define LISTBASE_FOREACH_INDEX(type, var, list, index_var) \
+  for (type var = (((void)(index_var = 0)), (type)((list)->first)); var != 
NULL; \
+       var = (type)(((Link *)(var))->next), index_var++)
+
 #ifdef __cplusplus
 }
 #endif

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to