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.
This commit is contained in:
parent
d5b5b228e4
commit
762e4cf221
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user