From 3cd0bb5783d3ef33483ba9a98859e9ce9deb2425 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 25 Jul 2015 16:42:50 +0200 Subject: [PATCH] common/array.h: add macro `foreach_reverse` Ref: https://github.com/awesomeWM/awesome/pull/340 --- common/array.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/array.h b/common/array.h index 72ab0da4..b988621f 100644 --- a/common/array.h +++ b/common/array.h @@ -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) { \