diff options
| -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; \ |
