diff options
| -rw-r--r-- | docs/ccommon_api.md | 6 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 7 |
2 files changed, 9 insertions, 4 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index be23dc36..2c0ea4c2 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -302,8 +302,10 @@ cmap_str_iter it, it1 = ..., it2 = ...; c_find_in(it, csmap_str, it1, it2, cstr_contains(it.ref, "hello")); if (it.ref) cmap_str_erase_at(&map, it); -// Erase all numbers less than 100: -c_erase_if(k, cvec_i, *k.ref < 100); +// Erase all strings containing "hello": +// Note 1: iter i need not be declared. +// Note 2: variables index and count can be accessed in predicate. +c_erase_if(i, csmap_str, map, cstr_contains(i.ref, "hello")); ``` ### c_new, c_alloc, c_alloc_n, c_drop, c_make diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index c6ec4529..2e84633c 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -280,10 +280,13 @@ STC_INLINE void crange_next(crange_iter* it) } while (0) #define c_erase_if(it, C, cnt, pred) do { \ + size_t index = 0, count = 0; \ C##_iter it = C##_begin(&cnt); \ - while (it.ref) \ - if (pred) it = C##_erase_at(&cnt, it); \ + while (it.ref) { \ + if (pred) it = C##_erase_at(&cnt, it), ++count; \ else C##_next(&it); \ + ++index; \ + } \ } while (0) #endif // CCOMMON_H_INCLUDED |
