summaryrefslogtreecommitdiffhomepage
path: root/docs
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-05-04 16:56:01 +0200
committerTyge Løvset <[email protected]>2022-05-04 16:56:01 +0200
commit691681356bf19ba112e7d332c07c986089ac16e4 (patch)
treed0c9931055bfd1de74ad45a649adfd1f412d9a56 /docs
parent93aa7a0e68a1c5bc65feed583db27686e813bb2a (diff)
downloadSTC-modified-691681356bf19ba112e7d332c07c986089ac16e4.tar.gz
STC-modified-691681356bf19ba112e7d332c07c986089ac16e4.zip
Added c_find_if, c_find_it macros: linear search in containers. Removed c_apply_cnt macro.
Diffstat (limited to 'docs')
-rw-r--r--docs/ccommon_api.md12
1 files changed, 9 insertions, 3 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index 41a88065..6922bf3a 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -167,7 +167,7 @@ c_forrange (i, int, 30, 0, -5) printf(" %d", i);
// 30 25 20 15 10 5
```
-### c_apply, c_apply_arr, c_apply_cnt, c_pair
+### c_apply, c_apply_arr, c_pair, c_find_if, c_find_it
**c_apply** applies an expression on a container with each of the elements in the given array:
```c
// apply multiple push_backs
@@ -178,8 +178,14 @@ 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));
-// add keys from a map to a vec.
-c_apply_cnt(v, cvec_i_push_back(&vec, v.first), cmap_i, map);
+// find_if, find_it: linear search
+int* v;
+c_find_if (v, cvec_i, vec, *v == 2);
+if (v) printf("%d\n", *v);
+
+cvec_i_iter it;
+c_find_it (it, cvec_i, vec, *it.ref == 2);
+cvec_i_erase_at(&vec, it); // assume found
```
### c_new, c_alloc, c_alloc_n, c_drop, c_make