diff options
| author | Tyge Løvset <[email protected]> | 2022-05-06 17:42:58 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-05-06 17:42:58 +0200 |
| commit | d9dc93a90e1ac0a42e946be52b169e1175377c4f (patch) | |
| tree | 255b12b7313d1a85d0a2147f27404d59e40ae43c /docs/ccommon_api.md | |
| parent | 9df37980d5801d4251db29fb33d8f8fa94570a2b (diff) | |
| download | STC-modified-d9dc93a90e1ac0a42e946be52b169e1175377c4f.tar.gz STC-modified-d9dc93a90e1ac0a42e946be52b169e1175377c4f.zip | |
Changed find_if() again. Now 3 iterator variants only.
Diffstat (limited to 'docs/ccommon_api.md')
| -rw-r--r-- | docs/ccommon_api.md | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index ef0ae621..95f1c6bb 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -172,25 +172,30 @@ c_forrange (i, int, 30, 0, -5) printf(" %d", i); ```c // apply multiple push_backs c_apply(v, cvec_i_push_back(&vec, v), int, {1, 2, 3}); + // inserts to existing map c_apply(v, cmap_i_insert(&map, c_pair(v)), cmap_i_raw, { {4, 5}, {6, 7} }); int arr[] = {1, 2, 3}; c_apply_arr(v, cvec_i_push_back(&vec, v), int, arr, c_arraylen(arr)); ``` -**c_find_if**, **c_find_it** searches linearily in containers using a predicate +**c_find_if**, **c_find_in** searches linearily in containers using a predicate ``` -int* v; -c_find_if (cvec_i, vec, v, *v == 2); -if (v) printf("%d\n", *v); +// NOTE: it.ref is NULL if not found, not cvec_i_end(&vec).ref +// This makes it easier to test. +cvec_i_iter it; -c_find_if (cvec_i, vec, v, index == 2); // index is internal in find_if. -if (v) printf("%d\n", *v); // 3 +// Search the the whole vec +c_find_if(cvec_i, vec, it, *it.ref == 2); +if (it.ref) printf("%d\n", *it.ref); -// use iterator: -cvec_i_iter it; -c_find_it (cvec_i, vec, it, *it.ref == 2); -cvec_i_erase_at(&vec, it); // assume found +// Search from iter's current position +c_find_from(cvec_i, vec, it, index == 2); // index is internal in find_if. +if (it.ref) printf("%d\n", *it.ref); // 3 + +// Search in the range +c_find_in(csmap_str, it1, it2, it, cstr_contains(*it.ref, "hello")); +cmap_str_erase_at(&map, it); // assume found ``` ### c_new, c_alloc, c_alloc_n, c_drop, c_make |
