diff options
| author | Tyge Løvset <[email protected]> | 2023-02-08 16:16:49 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-02-08 17:18:24 +0100 |
| commit | c4441f5fc665194fbd7a894a67a64a08c3beac42 (patch) | |
| tree | 82f231b6e8fcb75625166f98aa785baaa265a3d6 /include/stc/algo/filter.h | |
| parent | 673dd5319a488d4b702b94dd9aeda4e497ae4fbc (diff) | |
| download | STC-modified-c4441f5fc665194fbd7a894a67a64a08c3beac42.tar.gz STC-modified-c4441f5fc665194fbd7a894a67a64a08c3beac42.zip | |
Changed to use lowercase flow-control macros in examples (uppercase will still be supported). Improved many examples to use c_make() to init containers.
Diffstat (limited to 'include/stc/algo/filter.h')
| -rw-r--r-- | include/stc/algo/filter.h | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/include/stc/algo/filter.h b/include/stc/algo/filter.h index 9037c984..b2b59fa6 100644 --- a/include/stc/algo/filter.h +++ b/include/stc/algo/filter.h @@ -28,15 +28,14 @@ int main() { - c_WITH (cstack_int stk = {0}, cstack_int_drop(&stk)) { - c_FORLIST (i, int, {1, 2, 3, 4, 5, 6, 7, 8, 9}) - cstack_int_push(&stk, i); - - c_FOREACH (i, cstack_int, stk) + c_with (cstack_int stk = c_make(cstack_int, {1, 2, 3, 4, 5, 6, 7, 8, 9}), + cstack_int_drop(&stk)) + { + c_foreach (i, cstack_int, stk) printf(" %d", *i.ref); puts(""); - c_FORFILTER (i, cstack_int, stk + c_forfilter (i, cstack_int, stk , c_flt_skipwhile(i, *i.ref < 3) && (*i.ref & 1) == 0 // even only , c_flt_take(i, 2)) // break after 2 @@ -59,15 +58,15 @@ int main() #define c_flt_skipwhile(i, pred) ((i).s2[(i).s2top++] |= !(pred)) #define c_flt_takewhile(i, pred) !c_flt_skipwhile(i, pred) -#define c_FORFILTER(...) c_MACRO_OVERLOAD(c_FORFILTER, __VA_ARGS__) +#define c_forfilter(...) c_MACRO_OVERLOAD(c_forfilter, __VA_ARGS__) -#define c_FORFILTER_4(i, C, cnt, filter) \ - c_FORFILTER_B(i, C, C##_begin(&cnt), filter) +#define c_forfilter_4(i, C, cnt, filter) \ + c_forfilter_B(i, C, C##_begin(&cnt), filter) -#define c_FORFILTER_5(i, C, cnt, filter, cond) \ - c_FORFILTER_B(i, C, C##_begin(&cnt), filter) if (!(cond)) break; else +#define c_forfilter_5(i, C, cnt, filter, cond) \ + c_forfilter_B(i, C, C##_begin(&cnt), filter) if (!(cond)) break; else -#define c_FORFILTER_B(i, C, start, filter) \ +#define c_forfilter_B(i, C, start, filter) \ for (struct {C##_iter it; C##_value *ref; \ uint32_t s1[c_NFILTERS], index, count; \ bool s2[c_NFILTERS]; uint8_t s1top, s2top;} \ |
