tllist: cast away const in tll_{r,}foreach()

This allows us to iterate const lists.
This commit is contained in:
Daniel Eklöf 2018-12-15 11:46:34 +01:00
parent ee156c8dc7
commit bda77a83f7

View file

@ -82,16 +82,16 @@
* } * }
*/ */
#define tll_foreach(list, it) \ #define tll_foreach(list, it) \
for (__typeof((list).head) it = (list).head, \ for (__typeof__(*(list).head) *it = (list).head, \
it_next = it != NULL ? it->next : NULL; \ *it_next = it != NULL ? it->next : NULL; \
it != NULL; \ it != NULL; \
it = it_next, \ it = it_next, \
it_next = it_next != NULL ? it_next->next : NULL) it_next = it_next != NULL ? it_next->next : NULL)
/* Same as tll_foreach(), but iterates backwards */ /* Same as tll_foreach(), but iterates backwards */
#define tll_rforeach(list, it) \ #define tll_rforeach(list, it) \
for (__typeof((list).tail) it = (list).tail, \ for (__typeof__(*(list).tail) *it = (list).tail, \
it_prev = it != NULL ? it->prev : NULL; \ *it_prev = it != NULL ? it->prev : NULL; \
it != NULL; \ it != NULL; \
it = it_prev, \ it = it_prev, \
it_prev = it_prev != NULL ? it_prev->prev : NULL) it_prev = it_prev != NULL ? it_prev->prev : NULL)