diff options
author | Hans Goudey <h.goudey@me.com> | 2020-08-19 04:38:18 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-08-19 04:38:18 +0300 |
commit | ffa8e7579916609b4ddd4dda031cf2a3a7eaefb1 (patch) | |
tree | bb883bb0b5c6915f79e1da692b976b1f30f4cc31 /source/blender/blenlib | |
parent | 78d6c273b75363e9ecc28a92ecc8b320e4baad1d (diff) |
BLI Listbase: Add iterator macro that increments an index
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_listbase.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index fa7cf7a1847..aff80a2bd86 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -171,6 +171,15 @@ struct LinkData *BLI_genericNodeN(void *data); #define LISTBASE_FOREACH(type, var, list) \ for (type var = (type)((list)->first); var != NULL; var = (type)(((Link *)(var))->next)) +/** + * A version of #LISTBASE_FOREACH that supports incrementing an index variable at every step. + * Including this in the macro helps prevent mistakes where "continue" mistakenly skips the + * incrementation. + */ +#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++) + #define LISTBASE_FOREACH_BACKWARD(type, var, list) \ for (type var = (type)((list)->last); var != NULL; var = (type)(((Link *)(var))->prev)) |