diff options
| author | Tyge Løvset <[email protected]> | 2022-09-23 07:15:41 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-09-23 07:15:41 +0200 |
| commit | 34bec4fdf406caff8492d53f0afc80df5d75bba4 (patch) | |
| tree | 94252139eb34cb37f561ec5a6b9513629b2a81a5 /docs | |
| parent | d70bcf4d875c14da30a39acfc37d00391cc1e7a9 (diff) | |
| download | STC-modified-34bec4fdf406caff8492d53f0afc80df5d75bba4.tar.gz STC-modified-34bec4fdf406caff8492d53f0afc80df5d75bba4.zip | |
Deprecated c_forarray, c_forarray_p macros - both replaced by c_forlist, and is consistent with other c_for* macros.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/carc_api.md | 18 | ||||
| -rw-r--r-- | docs/cbox_api.md | 4 | ||||
| -rw-r--r-- | docs/ccommon_api.md | 24 | ||||
| -rw-r--r-- | docs/cdeq_api.md | 4 | ||||
| -rw-r--r-- | docs/clist_api.md | 16 | ||||
| -rw-r--r-- | docs/cmap_api.md | 8 | ||||
| -rw-r--r-- | docs/cset_api.md | 8 | ||||
| -rw-r--r-- | docs/csmap_api.md | 8 | ||||
| -rw-r--r-- | docs/csset_api.md | 8 | ||||
| -rw-r--r-- | docs/cvec_api.md | 4 |
10 files changed, 49 insertions, 53 deletions
diff --git a/docs/carc_api.md b/docs/carc_api.md index 56f8ff2e..d563f2f8 100644 --- a/docs/carc_api.md +++ b/docs/carc_api.md @@ -102,20 +102,20 @@ int main() // POPULATE s1 with shared pointers to Map: Map *map; - map = Stack_push(&s1, Arc_from(Map_init()))->get; // push empty map to s1. - c_forarray (Map_raw, v, { {"Joey", 1990}, {"Mary", 1995}, {"Joanna", 1992}}) { - Map_emplace(map, v->first, v->second); // populate it. + map = Stack_push(&s1, Arc_make(Map_init()))->get; // push empty map to s1. + c_forlist (i, Map_raw, {{"Joey", 1990}, {"Mary", 1995}, {"Joanna", 1992}}) { + Map_emplace(map, c_pair(i.ref)); // populate it. } - map = Stack_push(&s1, Arc_from(Map_init()))->get; - c_forarray (Map_raw, v, { {"Rosanna", 2001}, {"Brad", 1999}, {"Jack", 1980} }) { - Map_emplace(map, v->first, v->second); + map = Stack_push(&s1, Arc_make(Map_init()))->get; + c_forlist (i, Map_raw, {{"Rosanna", 2001}, {"Brad", 1999}, {"Jack", 1980}}) { + Map_emplace(map, c_pair(i.ref)); } // POPULATE s2: - map = Stack_push(&s2, Arc_from(Map_init()))->get; - c_forarray (Map_raw, v, { {"Steve", 1979}, {"Rick", 1974}, {"Tracy", 2003} }) { - Map_emplace(map, v->first, v->second); + map = Stack_push(&s2, Arc_make(Map_init()))->get; + c_forlist (i, Map_raw, {{"Steve", 1979}, {"Rick", 1974}, {"Tracy", 2003}}) { + Map_emplace(map, c_pair(i.ref)); } // Share two Maps from s1 with s2 by cloning(=sharing) the carcs: diff --git a/docs/cbox_api.md b/docs/cbox_api.md index 6686dde5..43fa46b0 100644 --- a/docs/cbox_api.md +++ b/docs/cbox_api.md @@ -91,8 +91,8 @@ int main() c_auto (IVec, vec) // declare and init vec, call drop at scope exit c_auto (ISet, set) // similar { - c_forarray (int, v, {2021, 2012, 2022, 2015}) - IVec_emplace(&vec, *v); // same as: IVec_push(&vec, IBox_from(*v)); + c_forlist (i, int, {2021, 2012, 2022, 2015}) + IVec_emplace(&vec, *i.ref); // same as: IVec_push(&vec, IBox_from(*i.ref)); printf("vec:"); c_foreach (i, IVec, vec) diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 8a805cef..403d8ef9 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -138,24 +138,20 @@ from a `c_auto` scope: } // for ``` -### c_forarray, c_forarray_p +### c_forlist Iterate compound literal array elements ```c // apply multiple push_backs -c_forarray (int, v, {1, 2, 3}) - cvec_i_push_back(&vec, *v); +c_forlist (i, int, {1, 2, 3}) + cvec_i_push_back(&vec, *i.ref); // insert in existing map -c_forarray (cmap_ii_raw, v, { {4, 5}, {6, 7} }) - cmap_ii_insert(&map, v->first, v->second); +c_forlist (i, cmap_ii_raw, { {4, 5}, {6, 7} }) + cmap_ii_insert(&map, i.ref->first, i.ref->second); -// even define an anonymous struct inside it (no commas allowed) -c_forarray (struct { int a; int b; }, v, { {1, 2}, {3, 4}, {5, 6} }) - printf("(%d %d) ", v->a, v->b); - -// `c_forarray_p` is required for pointer type elements -c_forarray_p (const char*, v, {"Hello", "crazy", "world"}) - cstack_s_push(&stk, *v); +// even string literals +c_forlist (i, const char*, {"Hello", "crazy", "world"}) + cstack_s_push(&stk, *i.ref); ``` ### c_foreach, c_forpair @@ -172,8 +168,8 @@ c_forarray_p (const char*, v, {"Hello", "crazy", "world"}) #define i_tag ii #include <stc/csmap.h> ... -c_forarray (csmap_ii_value, v, { {23,1}, {3,2}, {7,3}, {5,4}, {12,5} }) - csmap_ii_insert(&map, v->first, v->second); +c_forlist (i, csmap_ii_value, { {23,1}, {3,2}, {7,3}, {5,4}, {12,5} }) + csmap_ii_insert(&map, i.ref->first, i.ref->second); c_foreach (i, csmap_ii, map) printf(" %d", i.ref->first); diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md index bfe2447c..969cecc2 100644 --- a/docs/cdeq_api.md +++ b/docs/cdeq_api.md @@ -111,8 +111,8 @@ int main() { printf(" %d", *i.ref); puts(""); - c_forarray (int, v, {1, 4, 5, 22, 33, 2}) - cdeq_i_push_back(&q, *v) + c_forlist (i, int, {1, 4, 5, 22, 33, 2}) + cdeq_i_push_back(&q, *i.ref) c_foreach (i, cdeq_i, q) printf(" %d", *i.ref); diff --git a/docs/clist_api.md b/docs/clist_api.md index 45caeb93..1b3c5b0b 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -111,8 +111,8 @@ Interleave *push_front()* / *push_back()* then *sort()*: int main() { DList list = DList_init(); - c_forarray (double, v, {10., 20., 30., 40., 50., 60., 70., 80., 90.}) - DList_push_back(&list, *v); + c_forlist (i, double, {10., 20., 30., 40., 50., 60., 70., 80., 90.}) + DList_push_back(&list, *i.ref); c_forrange (int, i, 1, 10) { if (i & 1) DList_push_front(&list, (double) i); @@ -152,8 +152,8 @@ int main () { clist_i L = clist_i_init(); - c_forarray (int, v, {10, 20, 30, 40, 50}) - clist_i_push_back(&L, *v); + c_forlist (i, int, {10, 20, 30, 40, 50}) + clist_i_push_back(&L, *i.ref); // 10 20 30 40 50 clist_i_iter it = clist_i_begin(&L); // ^ clist_i_next(&it); @@ -189,10 +189,10 @@ Splice `[30, 40]` from *L2* into *L1* before `3`: int main() { c_auto (clist_i, L1, L2) { - c_forarray (int, v, {1, 2, 3, 4, 5}) - clist_i_push_back(&L1, *v); - c_forarray (int, v, {10, 20, 30, 40, 50}) - clist_i_push_back(&L2, *v); + c_forlist (i, int, {1, 2, 3, 4, 5}) + clist_i_push_back(&L1, *i.ref); + c_forlist (i, int, {10, 20, 30, 40, 50}) + clist_i_push_back(&L2, *i.ref); clist_i_iter i = clist_i_advance(clist_i_begin(&L1), 2); clist_i_iter j1 = clist_i_advance(clist_i_begin(&L2), 2), j2 = clist_i_advance(j1, 2); diff --git a/docs/cmap_api.md b/docs/cmap_api.md index a9676e68..25366792 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -127,11 +127,11 @@ int main() // Create an unordered_map of three strings (that map to strings) c_auto (cmap_str, u) { - c_forarray (cmap_str_raw, v, { + c_forlist (i, cmap_str_raw, { {"RED", "#FF0000"}, {"GREEN", "#00FF00"}, {"BLUE", "#0000FF"} - }) cmap_str_emplace(&u, v->first, v->second); + }) cmap_str_emplace(&u, c_pair(i.ref)); // Iterate and print keys and values of unordered map c_foreach (n, cmap_str, u) { @@ -173,8 +173,8 @@ int main() c_auto (cmap_id, idnames) { - c_forarray (cmap_id_raw, v, { {100, "Red"}, {110, "Blue"} }) - cmap_id_emplace(&idnames, v->first, v->second); + c_forlist (i, cmap_id_raw, { {100, "Red"}, {110, "Blue"} }) + cmap_id_emplace(&idnames, c_pair(i.ref)); // replace existing mapped value: cmap_id_emplace_or_assign(&idnames, 110, "White"); diff --git a/docs/cset_api.md b/docs/cset_api.md index 2d3ab6e7..b2e7d0c8 100644 --- a/docs/cset_api.md +++ b/docs/cset_api.md @@ -86,11 +86,11 @@ int main () c_auto (cset_str, first, second) c_auto (cset_str, third, fourth) { - c_forarray_p (const char*, v, {"red", "green", "blue"}) - cset_str_emplace(&second, *v); + c_forlist (i, const char*, {"red", "green", "blue"}) + cset_str_emplace(&second, *i.ref); - c_forarray_p (const char*, v, {"orange", "pink", "yellow"}) - cset_str_emplace(&third, *v); + c_forlist (i, const char*, {"orange", "pink", "yellow"}) + cset_str_emplace(&third, *i.ref); cset_str_emplace(&fourth, "potatoes"); cset_str_emplace(&fourth, "milk"); diff --git a/docs/csmap_api.md b/docs/csmap_api.md index 91abaae3..0be14605 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -113,11 +113,11 @@ int main() // Create a sorted map of three strings (maps to string) c_auto (csmap_str, colors) // RAII { - c_forarray (csmap_str_raw, v, { + c_forlist (i, csmap_str_raw, { {"RED", "#FF0000"}, {"GREEN", "#00FF00"}, {"BLUE", "#0000FF"} - }) csmap_str_emplace(&colors, v->first, v->second); + }) csmap_str_emplace(&colors, c_pair(i.ref)); // Iterate and print keys and values of sorted map c_foreach (i, csmap_str, colors) { @@ -159,8 +159,8 @@ int main() csmap_id idnames = csmap_id_init(); c_defer (csmap_id_drop(&idnames)) { - c_forarray (csmap_id_raw, v, { {100, "Red"}, {110, "Blue"} }) - csmap_id_emplace(&idnames, v->first, v->second); + c_forlist (i, csmap_id_raw, { {100, "Red"}, {110, "Blue"} }) + csmap_id_emplace(&idnames, c_pair(i.ref)); // put replaces existing mapped value: csmap_id_emplace_or_assign(&idnames, 110, "White"); diff --git a/docs/csset_api.md b/docs/csset_api.md index f2667376..82b8eb09 100644 --- a/docs/csset_api.md +++ b/docs/csset_api.md @@ -85,11 +85,11 @@ c_auto (csset_str, fifth) c_auto (csset_str, first, second) c_auto (csset_str, third, fourth) { - c_forarray_p (const char*, v, {"red", "green", "blue"}) - csset_str_emplace(&second, *v); + c_forlist (i, const char*, {"red", "green", "blue"}) + csset_str_emplace(&second, *i.ref); - c_forarray_p (const char*, v, {"orange", "pink", "yellow"}) - csset_str_emplace(&third, *v); + c_forlist (i, const char*, {"orange", "pink", "yellow"}) + csset_str_emplace(&third, *i.ref); csset_str_emplace(&fourth, "potatoes"); csset_str_emplace(&fourth, "milk"); diff --git a/docs/cvec_api.md b/docs/cvec_api.md index 588299fe..dca273aa 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -124,8 +124,8 @@ int main() cvec_int_push(&vec, 13); // Append a set of numbers - c_forarray (int, v, {7, 5, 16, 8}) - cvec_int_push(&vec, *v); + c_forlist (i, int, {7, 5, 16, 8}) + cvec_int_push(&vec, *i.ref); printf("initial:"); c_foreach (k, cvec_int, vec) { |
