common/array.h: add macro `foreach_reverse`

Ref: https://github.com/awesomeWM/awesome/pull/340
This commit is contained in:
Daniel Hahler 2015-07-25 16:42:50 +02:00
parent 292b95da01
commit 3cd0bb5783
1 changed files with 9 additions and 0 deletions

View File

@ -50,6 +50,15 @@
(var = &(array).tab[__foreach_index_##var]); \
++__foreach_index_##var)
#define foreach_reverse(var, array) \
for(int __foreach_index_##var = (array).len-1; \
__foreach_index_##var > -1; \
__foreach_index_##var = -1) \
for(typeof((array).tab) var = &(array).tab[__foreach_index_##var]; \
(__foreach_index_##var > -1) && \
(var = &(array).tab[__foreach_index_##var]); \
--__foreach_index_##var)
/** Common array functions */
#define ARRAY_COMMON_FUNCS(type_t, pfx, dtor) \
static inline pfx##_array_t * pfx##_array_new(void) { \