diff options
| author | Tyge Løvset <[email protected]> | 2022-08-05 09:20:47 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-08-05 09:20:47 +0200 |
| commit | 94f94957919292b572ea74a30dab5305eaf64808 (patch) | |
| tree | 6026ca73187454f374dd348ab59502025bf013d6 | |
| parent | f738106b75d9c4d7998294ffac9ee43f04e18667 (diff) | |
| download | STC-modified-94f94957919292b572ea74a30dab5305eaf64808.tar.gz STC-modified-94f94957919292b572ea74a30dab5305eaf64808.zip | |
Reduce usage of c_apply() macro.
| -rw-r--r-- | docs/clist_api.md | 8 | ||||
| -rw-r--r-- | docs/cmap_api.md | 7 | ||||
| -rw-r--r-- | docs/cpque_api.md | 8 | ||||
| -rw-r--r-- | examples/arc_containers.c | 19 | ||||
| -rw-r--r-- | examples/box.c | 4 | ||||
| -rw-r--r-- | examples/inits.c | 4 | ||||
| -rw-r--r-- | examples/regex2.c | 2 |
7 files changed, 31 insertions, 21 deletions
diff --git a/docs/clist_api.md b/docs/clist_api.md index e870c8c6..a3a59b7c 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -103,15 +103,17 @@ Interleave *push_front()* / *push_back()* then *sort()*: ```c #define i_val double #define i_tag d +#define i_extern // link with sort() fn. #include <stc/clist.h> #include <stdio.h> int main() { + double dv[] = { 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0 }; + clist_d list = clist_d_init(); - c_apply(v, clist_d_push_back(&list, *v), double, { - 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0 - }); + c_forrange (i, c_arraylen(dv); ++i) + clist_d_push_back(&list, dv[i]); c_forrange (int, i, 1, 10) { if (i & 1) clist_d_push_front(&list, (float) i); diff --git a/docs/cmap_api.md b/docs/cmap_api.md index bb760b4d..89d7f408 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -398,11 +398,14 @@ static inline RViking Viking_toraw(const Viking* vp) { int main() { c_auto (Vikings, vikings) { - c_apply(v, Vikings_emplace(&vikings, c_pair(v)), Vikings_raw, { + Vikings_raw arr[] = { { {"Einar", "Norway"}, 20 }, { {"Olaf", "Denmark"}, 24 }, { {"Harald", "Iceland"}, 12 }, - }); + }; + c_forrange (i, c_arraylen(arr)) + Vikings_emplace(&vikings, arr[i].first, arr[i].second); + Vikings_emplace_or_assign(&vikings, (RViking){"Bjorn", "Sweden"}, 10); Vikings_value *v = Vikings_get_mut(&vikings, (RViking){"Einar", "Norway"}); diff --git a/docs/cpque_api.md b/docs/cpque_api.md index 12f5c3bc..8b990be8 100644 --- a/docs/cpque_api.md +++ b/docs/cpque_api.md @@ -75,10 +75,14 @@ int main() // Declare heap, with defered drop() c_auto (cpque_i, heap) { - // Push ten million random numbers to priority queue, plus some negative ones. + // Push ten million random numbers to priority queue. c_forrange (N) cpque_i_push(&heap, stc64_uniform(&rng, &dist)); - c_apply(v, cpque_i_push(&heap, *v), int, {-231, -32, -873, -4, -343}); + + // Add some negative ones. + int nums[] = {-231, -32, -873, -4, -343}; + c_forrange (i, c_arraylen(nums)) + cpque_i_push(&heap, nums[i]); // Extract and display the fifty smallest. c_forrange (50) { diff --git a/examples/arc_containers.c b/examples/arc_containers.c index 969825eb..e8716129 100644 --- a/examples/arc_containers.c +++ b/examples/arc_containers.c @@ -32,19 +32,20 @@ int main() // POPULATE stack with shared pointers to Maps: Map *map; map = Stack_push(&stack, Arc_make(Map_init()))->get; - c_apply(v, Map_emplace(map, c_pair(v)), Map_raw, { - {"Joey", 1990}, {"Mary", 1995}, {"Joanna", 1992} - }); + Map_emplace(map, "Joey", 1990); + Map_emplace(map, "Mary", 1995); + Map_emplace(map, "Joanna", 1992); + map = Stack_push(&stack, Arc_make(Map_init()))->get; - c_apply(v, Map_emplace(map, c_pair(v)), Map_raw, { - {"Rosanna", 2001}, {"Brad", 1999}, {"Jack", 1980} - }); + Map_emplace(map, "Rosanna", 2001); + Map_emplace(map, "Brad", 1999); + Map_emplace(map, "Jack", 1980); // POPULATE list: map = List_push_back(&list, Arc_make(Map_init()))->get; - c_apply(v, Map_emplace(map, c_pair(v)), Map_raw, { - {"Steve", 1979}, {"Rick", 1974}, {"Tracy", 2003} - }); + Map_emplace(map, "Steve", 1979); + Map_emplace(map, "Rick", 1974); + Map_emplace(map, "Tracy", 2003); // Share two Maps from the stack with the list using emplace (clone the carc): List_push_back(&list, Arc_clone(stack.data[0])); diff --git a/examples/box.c b/examples/box.c index ef2ff28b..c7e649bf 100644 --- a/examples/box.c +++ b/examples/box.c @@ -41,7 +41,6 @@ int main() c_auto (PBox, p, q) { p = PBox_make(Person_new("Laura", "Palmer")); - q = PBox_clone(p); cstr_assign(&q.get->name, "Leland"); @@ -52,7 +51,8 @@ int main() Persons_push(&vec, PBox_make(Person_new("Audrey", "Home"))); // NB! Clone p and q to the vector using emplace_back() - c_apply(v, Persons_push(&vec, PBox_clone(*v)), PBox, {p, q}); + Persons_push(&vec, PBox_clone(p)); + Persons_push(&vec, PBox_clone(q)); c_foreach (i, Persons, vec) printf("%s %s\n", cstr_str(&i.ref->get->name), cstr_str(&i.ref->get->last)); diff --git a/examples/inits.c b/examples/inits.c index 608dd146..a2fb51cb 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -40,8 +40,8 @@ int main(void) const float nums[] = {4.0f, 2.0f, 5.0f, 3.0f, 1.0f}; // PRIORITY QUEUE - - c_apply_array(v, cpque_f_push(&floats, *v), const float, nums, c_arraylen(nums)); + c_forrange (i, c_arraylen(nums)) + cpque_f_push(&floats, nums[i]); puts("\npop and show high priorites first:"); while (! cpque_f_empty(&floats)) { diff --git a/examples/regex2.c b/examples/regex2.c index 672020f6..30602444 100644 --- a/examples/regex2.c +++ b/examples/regex2.c @@ -26,7 +26,7 @@ int main() c_foreach_match (j, &re, s[i].input) { c_forrange (k, cregex_captures(&re)) - printf(" submatch %d: %.*s\n", k, c_ARGsv(j.ref[k])); + printf(" submatch %d: %.*s\n", (int)k, c_ARGsv(j.ref[k])); puts(""); } } |
