diff options
| author | Tyge Løvset <[email protected]> | 2022-05-22 20:52:18 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-05-22 20:52:18 +0200 |
| commit | 1c3e7b683469904d224f3f8f1ee0096f1c5b1b9d (patch) | |
| tree | 826ca6560cd952996eb9793cb3356a9791753f2e /examples | |
| parent | 314a41be6b39b6c5967d79555dbf018dbc7eb5f6 (diff) | |
| download | STC-modified-1c3e7b683469904d224f3f8f1ee0096f1c5b1b9d.tar.gz STC-modified-1c3e7b683469904d224f3f8f1ee0096f1c5b1b9d.zip | |
Changed c_apply(v, ..) macro to make it more consistent with c_apply_arr(v, ..) and c_foreach (i, ..): v changed to a pointer - not value.
Note: also c_pair(v) is changed correspondingly, so usage with c_apply(v) is unchanged.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/box.c | 2 | ||||
| -rw-r--r-- | examples/city.c | 4 | ||||
| -rw-r--r-- | examples/csmap_find.c | 2 | ||||
| -rw-r--r-- | examples/csset_erase.c | 2 | ||||
| -rw-r--r-- | examples/inits.c | 4 | ||||
| -rw-r--r-- | examples/list.c | 2 | ||||
| -rw-r--r-- | examples/list_erase.c | 2 | ||||
| -rw-r--r-- | examples/list_splice.c | 4 | ||||
| -rw-r--r-- | examples/lower_bound.c | 4 | ||||
| -rw-r--r-- | examples/mmap.c | 2 | ||||
| -rw-r--r-- | examples/music_arc.c | 4 | ||||
| -rw-r--r-- | examples/new_list.c | 4 | ||||
| -rw-r--r-- | examples/new_map.c | 2 | ||||
| -rw-r--r-- | examples/person_arc.c | 2 | ||||
| -rw-r--r-- | examples/phonebook.c | 2 | ||||
| -rw-r--r-- | examples/prime.c | 1 | ||||
| -rw-r--r-- | examples/priority.c | 2 | ||||
| -rw-r--r-- | examples/shape.c | 4 | ||||
| -rw-r--r-- | examples/words.c | 2 |
19 files changed, 26 insertions, 25 deletions
diff --git a/examples/box.c b/examples/box.c index 423e9cb1..2f82a694 100644 --- a/examples/box.c +++ b/examples/box.c @@ -52,7 +52,7 @@ int main() Persons_push_back(&vec, PBox_make(Person_new("Audrey", "Home")));
// NB! Clone p and q to the vector using emplace_back()
- c_apply(v, Persons_push_back(&vec, PBox_clone(v)), PBox, {p, q});
+ c_apply(v, Persons_push_back(&vec, PBox_clone(*v)), PBox, {p, 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/city.c b/examples/city.c index d2178494..017c1c20 100644 --- a/examples/city.c +++ b/examples/city.c @@ -52,8 +52,8 @@ int main(void) {
struct City_s { const char *name, *country; float lat, lon; int pop; };
- c_apply(c, Cities_push(&cities, CityArc_make((City){cstr_from(c.name), cstr_from(c.country),
- c.lat, c.lon, c.pop})), struct City_s, {
+ c_apply(c, Cities_push(&cities, CityArc_make((City){cstr_from(c->name), cstr_from(c->country),
+ c->lat, c->lon, c->pop})), struct City_s, {
{"New York", "US", 4.3, 23.2, 9000000},
{"Paris", "France", 4.3, 23.2, 9000000},
{"Berlin", "Germany", 4.3, 23.2, 9000000},
diff --git a/examples/csmap_find.c b/examples/csmap_find.c index 9e3aba83..c3047110 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -62,7 +62,7 @@ int main() print_collection_cvec_istr(v); c_foreach (i, cvec_istr, cvec_istr_begin(&v), cvec_istr_end(&v)) - csmap_istr_emplace(&m1, c_pair(*i.ref)); + csmap_istr_emplace(&m1, c_pair(i.ref)); puts("The modified map m1 is (key, value):"); print_collection_csmap_istr(m1); diff --git a/examples/csset_erase.c b/examples/csset_erase.c index fe9977a9..3cfaa7f1 100644 --- a/examples/csset_erase.c +++ b/examples/csset_erase.c @@ -7,7 +7,7 @@ int main() {
c_auto (csset_int, set)
{
- c_apply(v, csset_int_insert(&set, v),
+ c_apply(v, csset_int_insert(&set, *v),
int, {30, 20, 80, 40, 60, 90, 10, 70, 50});
c_foreach (k, csset_int, set)
printf(" %d", *k.ref);
diff --git a/examples/inits.c b/examples/inits.c index 97d86389..ae86cb87 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -90,7 +90,7 @@ int main(void) // CVEC PAIR
c_auto (cvec_ip, pairs1) {
- c_apply(p, cvec_ip_push_back(&pairs1, p), ipair_t,
+ c_apply(p, cvec_ip_push_back(&pairs1, *p), ipair_t,
{{5, 6}, {3, 4}, {1, 2}, {7, 8}});
cvec_ip_sort(&pairs1);
@@ -102,7 +102,7 @@ int main(void) // CLIST PAIR
c_auto (clist_ip, pairs2) {
- c_apply(p, clist_ip_push_back(&pairs2, p), ipair_t,
+ c_apply(p, clist_ip_push_back(&pairs2, *p), ipair_t,
{{5, 6}, {3, 4}, {1, 2}, {7, 8}});
clist_ip_sort(&pairs2);
diff --git a/examples/list.c b/examples/list.c index b9f56f13..1b3ccdba 100644 --- a/examples/list.c +++ b/examples/list.c @@ -36,7 +36,7 @@ int main() { puts("");
clist_fx_clear(&list);
- c_apply(v, clist_fx_push_back(&list, v), int, {10, 20, 30, 40, 30, 50});
+ c_apply(v, clist_fx_push_back(&list, *v), int, {10, 20, 30, 40, 30, 50});
const double* v = clist_fx_get(&list, 30);
printf("found: %f\n", *v);
c_foreach (i, clist_fx, list) printf(" %g", *i.ref);
diff --git a/examples/list_erase.c b/examples/list_erase.c index 1e5d2e9b..19a00299 100644 --- a/examples/list_erase.c +++ b/examples/list_erase.c @@ -8,7 +8,7 @@ int main () {
c_auto (clist_int, L)
{
- c_apply(i, clist_int_push_back(&L, i), int, {10, 20, 30, 40, 50});
+ c_apply(i, clist_int_push_back(&L, *i), int, {10, 20, 30, 40, 50});
c_foreach (x, clist_int, L)
printf("%d ", *x.ref);
puts("");
diff --git a/examples/list_splice.c b/examples/list_splice.c index 754ec6fb..aaec506a 100644 --- a/examples/list_splice.c +++ b/examples/list_splice.c @@ -17,8 +17,8 @@ int main () { c_auto (clist_i, list1, list2) { - c_apply(v, clist_i_push_back(&list1, v), int, {1, 2, 3, 4, 5}); - c_apply(v, clist_i_push_back(&list2, v), int, {10, 20, 30, 40, 50}); + c_apply(v, clist_i_push_back(&list1, *v), int, {1, 2, 3, 4, 5}); + c_apply(v, clist_i_push_back(&list2, *v), int, {10, 20, 30, 40, 50}); print_ilist("list1:", list1); print_ilist("list2:", list2); diff --git a/examples/lower_bound.c b/examples/lower_bound.c index bb8fdf66..6039dd48 100644 --- a/examples/lower_bound.c +++ b/examples/lower_bound.c @@ -13,7 +13,7 @@ int main() {
int key, *res;
- c_apply(t, cvec_int_push(&vec, t), int, {
+ c_apply(t, cvec_int_push(&vec, *t), int, {
40, 600, 1, 7000, 2, 500, 30,
});
@@ -41,7 +41,7 @@ int main() {
int key, *res;
- c_apply(t, csset_int_push(&set, t), int, {
+ c_apply(t, csset_int_push(&set, *t), int, {
40, 600, 1, 7000, 2, 500, 30,
});
diff --git a/examples/mmap.c b/examples/mmap.c index 6ffd3a5d..f8e56dc3 100644 --- a/examples/mmap.c +++ b/examples/mmap.c @@ -35,7 +35,7 @@ int main() // list-initialize
struct { int first; const char* second; } vals[] =
{{2, "foo"}, {2, "bar"}, {3, "baz"}, {1, "abc"}, {5, "def"}};
- c_forrange (i, c_arraylen(vals)) insert(&mmap, c_pair(vals[i]));
+ c_forrange (i, c_arraylen(vals)) insert(&mmap, c_pair(&vals[i]));
print("#1", mmap);
// insert using value_type
diff --git a/examples/music_arc.c b/examples/music_arc.c index 24cb25f1..489a136f 100644 --- a/examples/music_arc.c +++ b/examples/music_arc.c @@ -31,7 +31,7 @@ void example3() {
c_auto (SongVec, vec, vec2)
{
- c_apply(v, SongVec_push_back(&vec, v), SongPtr, {
+ c_apply(v, SongVec_push_back(&vec, *v), SongPtr, {
SongPtr_make(Song_new("Bob Dylan", "The Times They Are A Changing")),
SongPtr_make(Song_new("Aretha Franklin", "Bridge Over Troubled Water")),
SongPtr_make(Song_new("Thalia", "Entre El Mar y Una Estrella"))
@@ -41,7 +41,7 @@ void example3() if (!cstr_equals(s.ref->get->artist, "Bob Dylan"))
SongVec_push_back(&vec2, SongPtr_clone(*s.ref));
- c_apply(v, SongVec_push_back(&vec2, v), SongPtr, {
+ c_apply(v, SongVec_push_back(&vec2, *v), SongPtr, {
SongPtr_make(Song_new("Michael Jackson", "Billie Jean")),
SongPtr_make(Song_new("Rihanna", "Stay")),
});
diff --git a/examples/new_list.c b/examples/new_list.c index 2b6b4636..20a64ad3 100644 --- a/examples/new_list.c +++ b/examples/new_list.c @@ -39,7 +39,7 @@ int main() clist_i32_push_back(&lst, 123); c_auto (clist_pnt, plst) { - c_apply(v, clist_pnt_push_back(&plst, v), + c_apply(v, clist_pnt_push_back(&plst, *v), Point, {{42, 14}, {32, 94}, {62, 81}}); clist_pnt_sort(&plst); @@ -49,7 +49,7 @@ int main() } c_auto (clist_float, flst) { - c_apply(v, clist_float_push_back(&flst, v), + c_apply(v, clist_float_push_back(&flst, *v), float, {123.3f, 321.2f, -32.2f, 78.2f}); c_foreach (i, clist_float, flst) printf(" %g", *i.ref); } diff --git a/examples/new_map.c b/examples/new_map.c index 2671790a..32a4ce68 100644 --- a/examples/new_map.c +++ b/examples/new_map.c @@ -61,7 +61,7 @@ int main() {"So long, friend", "see you around"},
});
- c_apply(v, cset_str_emplace(&sset, v), const char*, {
+ c_apply(v, cset_str_emplace(&sset, *v), const char*, {
"Hello, friend",
"Nice to see you again",
"So long, friend",
diff --git a/examples/person_arc.c b/examples/person_arc.c index 40707740..c77ca315 100644 --- a/examples/person_arc.c +++ b/examples/person_arc.c @@ -54,7 +54,7 @@ int main() Persons_push_back(&vec, PSPtr_make(Person_new("Audrey", "Home")));
// Clone/share p and q to the vector
- c_apply(v, Persons_push_back(&vec, PSPtr_clone(v)), PSPtr, {p, q});
+ c_apply(v, Persons_push_back(&vec, PSPtr_clone(*v)), PSPtr, {p, 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/phonebook.c b/examples/phonebook.c index b00a49a8..26f4ff9e 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -40,7 +40,7 @@ void print_phone_book(cmap_str phone_book) int main(int argc, char **argv)
{
c_auto (cset_str, names) {
- c_apply(v, cset_str_emplace(&names, v), const char*,
+ c_apply(v, cset_str_emplace(&names, *v), const char*,
{"Hello", "Cool", "True"});
c_foreach (i, cset_str, names) printf("%s ", cstr_str(i.ref));
puts("");
diff --git a/examples/prime.c b/examples/prime.c index 4d70ee24..aee0a89e 100644 --- a/examples/prime.c +++ b/examples/prime.c @@ -1,6 +1,7 @@ #include <stdio.h>
#include <math.h>
#include <time.h>
+
#include <stc/cbits.h>
cbits sieveOfEratosthenes(size_t n)
diff --git a/examples/priority.c b/examples/priority.c index 6e033386..66e400dd 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -20,7 +20,7 @@ int main() { cpque_i_push(&heap, stc64_uniform(&rng, &dist));
// push some negative numbers too.
- c_apply(v, cpque_i_push(&heap, v), int, {-231, -32, -873, -4, -343});
+ c_apply(v, cpque_i_push(&heap, *v), int, {-231, -32, -873, -4, -343});
c_forrange (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
diff --git a/examples/shape.c b/examples/shape.c index 816fdea4..04aecaa1 100644 --- a/examples/shape.c +++ b/examples/shape.c @@ -147,10 +147,10 @@ int main(void) Polygon* pol1 = Polygon_new();
Polygon* pol2 = Polygon_new();
- c_apply(p, Polygon_addPoint(pol1, p), Point,
+ c_apply(p, Polygon_addPoint(pol1, *p), Point,
{{50, 72}, {123, 73}, {127, 201}, {828, 333}});
- c_apply(p, Polygon_addPoint(pol2, p), Point,
+ c_apply(p, Polygon_addPoint(pol2, *p), Point,
{{5, 7}, {12, 7}, {12, 20}, {82, 33}, {17, 56}});
Shapes_push(&shapes, &tri1->base);
diff --git a/examples/words.c b/examples/words.c index 28de2638..8a86ba7f 100644 --- a/examples/words.c +++ b/examples/words.c @@ -13,7 +13,7 @@ int main1() c_auto (cvec_str, words) c_auto (cmap_str, word_map) { - c_apply(v, cvec_str_emplace_back(&words, v), const char*, { + c_apply(v, cvec_str_emplace_back(&words, *v), const char*, { "this", "sentence", "is", "not", "a", "sentence", "this", "sentence", "is", "a", "hoax" }); |
