diff options
-rw-r--r-- | linked_list.h | 12 | ||||
-rw-r--r-- | macro.h | 15 |
2 files changed, 27 insertions, 0 deletions
diff --git a/linked_list.h b/linked_list.h index 4199ba57..6136d35f 100644 --- a/linked_list.h +++ b/linked_list.h @@ -53,4 +53,16 @@ int APPEND(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* new ); int SIZE(LLIST(TYPE)) ( LLIST(TYPE)* llist ); int EMPTY(LLIST(TYPE)) ( LLIST(TYPE)* llist ); +/* Iterator */ + +// #define __BEG_LLIST(v, set) v = (set)->head +#define __BEG_LLIST(v, set) v = FIRST(set) +#define BEG_LLIST(T) LINK(T)* __BEG_LLIST + +#define __END_LLIST(var, set) var == (set)->tail +#define END_LLIST(T) __END_LLIST + +#define __NXT_LLIST(var, set) var = var->after +#define NXT_LLIST(T) __NXT_LLIST + #endif /* TYPE */ @@ -79,6 +79,21 @@ /* + * Iterator macros. + */ +#define FOR(T, var, set) for( \ + BEG_ ## T (var, set); \ + END_ ## T (var, set); \ + NXT_ ## T (var, set)) + +/* Example int implementation + * FOR(int, i, 10) { } */ + +#define BEG_int(i, set) int i = 0 +#define NXT_int(i, set) i++ +#define END_int(i, set) i < set + +/* * General functions that different container types may implement. * Actuall implementation and type signature is mostly left to * individual implementations. |