diff options
| author | Tyge Lovset <[email protected]> | 2023-03-23 08:34:23 +0100 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2023-03-23 08:34:23 +0100 |
| commit | 1200858a3555baf682c9c83ef6c00e1ed1fcd429 (patch) | |
| tree | 2f7129bb5653828a6fb7790a02c9e04d45773942 /include | |
| parent | e6a25eaaf4687ff99d0d719d0b32ad512156039e (diff) | |
| download | STC-modified-1200858a3555baf682c9c83ef6c00e1ed1fcd429.tar.gz STC-modified-1200858a3555baf682c9c83ef6c00e1ed1fcd429.zip | |
Internal in filter. c_xxx_if() macros now all have an _index var that can be used in the predicate.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/algo/filter.h | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/include/stc/algo/filter.h b/include/stc/algo/filter.h index 1978ea43..a04dfcb5 100644 --- a/include/stc/algo/filter.h +++ b/include/stc/algo/filter.h @@ -72,24 +72,25 @@ int main() #define c_find_if(...) c_MACRO_OVERLOAD(c_find_if, __VA_ARGS__) #define c_find_if_4(it, C, cnt, pred) do { \ - intptr_t index = 0; \ + intptr_t _index = 0; \ for (it = C##_begin(&cnt); it.ref && !(pred); C##_next(&it)) \ - ++index; \ + ++_index; \ } while (0) #define c_find_if_5(it, C, start, end, pred) do { \ - intptr_t index = 0; \ + intptr_t _index = 0; \ const C##_value* _endref = (end).ref; \ for (it = start; it.ref != _endref && !(pred); C##_next(&it)) \ - ++index; \ + ++_index; \ if (it.ref == _endref) it.ref = NULL; \ } while (0) -// Use with: clist, cmap, cset, csmap, csset, cstr: +// Use with: clist, cmap, cset, csmap, csset: #define c_erase_if(it, C, cnt, pred) do { \ C* _cnt = &cnt; \ - for (C##_iter it = C##_begin(_cnt); it.ref;) { \ + intptr_t _index = 0; \ + for (C##_iter it = C##_begin(_cnt); it.ref; ++_index) { \ if (pred) it = C##_erase_at(_cnt, it); \ else C##_next(&it); \ } \ @@ -99,11 +100,11 @@ int main() // Use with: cstack, cvec, cdeq, cqueue: #define c_eraseremove_if(it, C, cnt, pred) do { \ C* _cnt = &cnt; \ - intptr_t _n = 0; \ + intptr_t _n = 0, _index = 0; \ C##_iter it = C##_begin(_cnt), _i; \ while (it.ref && !(pred)) \ C##_next(&it); \ - for (_i = it; it.ref; C##_next(&it)) \ + for (_i = it; it.ref; C##_next(&it), ++_index) \ if (pred) C##_value_drop(it.ref), ++_n; \ else *_i.ref = *it.ref, C##_next(&_i); \ _cnt->_len -= _n; \ |
