summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--docs/carc_api.md4
-rw-r--r--docs/ccommon_api.md2
-rw-r--r--docs/cmap_api.md12
-rw-r--r--examples/arc_containers.c4
-rw-r--r--examples/books.c2
-rw-r--r--examples/city.c3
-rw-r--r--examples/gauss2.c4
-rw-r--r--examples/hashmap.c2
-rw-r--r--examples/inits.c2
-rw-r--r--examples/mapmap.c2
-rw-r--r--examples/new_smap.c4
-rw-r--r--examples/rawptr_elements.c2
-rw-r--r--examples/sso_map.c4
-rw-r--r--examples/vikings.c4
-rw-r--r--include/stc/ccommon.h4
15 files changed, 28 insertions, 27 deletions
diff --git a/docs/carc_api.md b/docs/carc_api.md
index 52809165..d0d90300 100644
--- a/docs/carc_api.md
+++ b/docs/carc_api.md
@@ -135,14 +135,14 @@ int main()
puts("STACKS");
c_foreach (i, Stack, stack) {
c_forpair (name, year, Map, *i.ref->get)
- printf(" %s:%d", cstr_str(&_.name), _.year);
+ printf(" %s:%d", cstr_str(_.name), *_.year);
puts("");
}
puts("LIST");
c_foreach (i, List, list) {
c_forpair (name, year, Map, *i.ref->get)
- printf(" %s:%d", cstr_str(&_.name), _.year);
+ printf(" %s:%d", cstr_str(_.name), *_.year);
puts("");
}
}
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index 249f2523..9d2baea6 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -141,7 +141,7 @@ c_foreach (i, csmap_ii, it, csmap_ii_end(&map))
// out: 7 12 23
c_forpair (id, count, csmap_ii, map)
- printf(" (%d %d)", _.id, _.count);
+ printf(" (%d %d)", *_.id, *_.count);
// out: (3 2) (5 4) (7 3) (12 5) (23 1)
```
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 02052847..58d33534 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -217,7 +217,7 @@ int main()
cmap_vi_insert(&vecs, (Vec3i){100, 100, 100}, 4);
c_forpair (vec, num, cmap_vi, vecs)
- printf("{ %3d, %3d, %3d }: %d\n", _.vec.x, _.vec.y, _.vec.z, _.num);
+ printf("{ %3d, %3d, %3d }: %d\n", _.vec->x, _.vec->y, _.vec->z, *_.num);
}
}
```
@@ -250,7 +250,7 @@ int main()
cmap_iv_insert(&vecs, 4, (Vec3i){100, 100, 100});
c_forpair (num, vec, cmap_iv, vecs)
- printf("%d: { %3d, %3d, %3d }\n", _.num, _.vec.x, _.vec.y, _.vec.z);
+ printf("%d: { %3d, %3d, %3d }\n", *_.num, _.vec->x, _.vec->y, _.vec->z);
}
}
```
@@ -322,8 +322,8 @@ int main()
}
// Print the status of the vikings.
- c_forpair (viking, hp, Vikings, vikings) {
- printf("%s of %s has %d hp\n", cstr_str(&_.viking.name), cstr_str(&_.viking.country), _.hp);
+ c_forpair (vik, hp, Vikings, vikings) {
+ printf("%s of %s has %d hp\n", cstr_str(&_.vik->name), cstr_str(&_.vik->country), *_.hp);
}
}
}
@@ -406,8 +406,8 @@ int main()
Vikings_value *v = Vikings_get_mut(&vikings, (RViking){"Einar", "Norway"});
if (v) v->second += 3; // add 3 hp points to Einar
- c_forpair (viking, health, Vikings, vikings) {
- printf("%s of %s has %d hp\n", cstr_str(&_.viking.name), cstr_str(&_.viking.country), _.health);
+ c_forpair (vik, health, Vikings, vikings) {
+ printf("%s of %s has %d hp\n", cstr_str(&_.vik->name), cstr_str(&_.vik->country), *_.health);
}
}
}
diff --git a/examples/arc_containers.c b/examples/arc_containers.c
index a58e24ab..f9c14123 100644
--- a/examples/arc_containers.c
+++ b/examples/arc_containers.c
@@ -62,13 +62,13 @@ int main()
puts("STACKS");
c_foreach (i, Stack, stack) {
c_forpair (name, year, Map, *i.ref->get)
- printf(" %s:%d", cstr_str(&_.name), _.year);
+ printf(" %s:%d", cstr_str(_.name), *_.year);
puts("");
}
puts("LIST");
c_foreach (i, List, list) {
c_forpair (name, year, Map, *i.ref->get)
- printf(" %s:%d", cstr_str(&_.name), _.year);
+ printf(" %s:%d", cstr_str(_.name), *_.year);
puts("");
}
}
diff --git a/examples/books.c b/examples/books.c
index b35f5b36..b891388d 100644
--- a/examples/books.c
+++ b/examples/books.c
@@ -54,7 +54,7 @@ int main()
// Iterate over everything.
c_forpair (book, review, cmap_str, book_reviews) {
- printf("%s: \"%s\"\n", cstr_str(&_.book), cstr_str(&_.review));
+ printf("%s: \"%s\"\n", cstr_str(_.book), cstr_str(_.review));
}
}
}
diff --git a/examples/city.c b/examples/city.c
index 017c1c20..fb863e3c 100644
--- a/examples/city.c
+++ b/examples/city.c
@@ -75,7 +75,8 @@ int main(void)
printf("\nMap:\n");
c_forpair (id, city, CityMap, map)
- printf("id:%d, city:%s, %d, use:%ld\n", _.id, cstr_str(&_.city.get->name), _.city.get->population, CityArc_use_count(_.city));
+ printf("id:%d, city:%s, %d, use:%ld\n", *_.id, cstr_str(&_.city->get->name),
+ _.city->get->population, CityArc_use_count(*_.city));
puts("");
}
}
diff --git a/examples/gauss2.c b/examples/gauss2.c
index 9558afd3..5ded4714 100644
--- a/examples/gauss2.c
+++ b/examples/gauss2.c
@@ -31,10 +31,10 @@ int main()
// Print the gaussian bar chart
c_auto (cstr, bar)
c_forpair (index, count, csmap_int, mhist) {
- size_t n = (size_t) (_.count * StdDev * Scale * 2.5 / (float)N);
+ size_t n = (size_t) (*_.count * StdDev * Scale * 2.5 / (float)N);
if (n > 0) {
cstr_resize(&bar, n, '*');
- printf("%4d %s\n", _.index, cstr_str(&bar));
+ printf("%4d %s\n", *_.index, cstr_str(&bar));
}
}
}
diff --git a/examples/hashmap.c b/examples/hashmap.c
index e81a0405..f39a3904 100644
--- a/examples/hashmap.c
+++ b/examples/hashmap.c
@@ -41,7 +41,7 @@ int main(void) {
puts("");
c_forpair (contact, number, cmap_str, contacts) {
- printf("Calling %s: %s\n", cstr_str(&_.contact), call(cstr_str(&_.number)));
+ printf("Calling %s: %s\n", cstr_str(_.contact), call(cstr_str(_.number)));
}
puts("");
}
diff --git a/examples/inits.c b/examples/inits.c
index ae86cb87..ae64f6ec 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -83,7 +83,7 @@ int main(void)
cmap_cnt_emplace(&countries, "Finland", 0).ref->second += 20;
c_forpair (country, health, cmap_cnt, countries)
- printf("%s: %d\n", cstr_str(&_.country), _.health);
+ printf("%s: %d\n", cstr_str(_.country), *_.health);
puts("");
}
diff --git a/examples/mapmap.c b/examples/mapmap.c
index 668ec9e8..51a5ce59 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -60,7 +60,7 @@ int main(void)
c_foreach (i, Departments, map)
c_forpair (name, email, People, i.ref->second)
- printf("%s: %s - %s\n", cstr_str(&i.ref->first), cstr_str(&_.name), cstr_str(&_.email));
+ printf("%s: %s - %s\n", cstr_str(&i.ref->first), cstr_str(_.name), cstr_str(_.email));
puts("");
printf("found: %d\n", contains(&map, "Nick Denton"));
diff --git a/examples/new_smap.c b/examples/new_smap.c
index a25dcfa2..38822585 100644
--- a/examples/new_smap.c
+++ b/examples/new_smap.c
@@ -53,7 +53,7 @@ int main()
{{62, 81}, 3},
});
c_forpair (p, i, PMap, pmap)
- printf(" (%d,%d: %d)", _.p.x, _.p.y, _.i);
+ printf(" (%d,%d: %d)", _.p->x, _.p->y, *_.i);
puts("");
}
@@ -64,7 +64,7 @@ int main()
{"This is the time", "for all good things"},
});
c_forpair (i, j, SMap, smap)
- printf(" (%s: %s)\n", cstr_str(&_.i), cstr_str(&_.j));
+ printf(" (%s: %s)\n", cstr_str(_.i), cstr_str(_.j));
}
c_auto (SSet, sset) {
diff --git a/examples/rawptr_elements.c b/examples/rawptr_elements.c
index a6e195a9..f31f9abd 100644
--- a/examples/rawptr_elements.c
+++ b/examples/rawptr_elements.c
@@ -61,6 +61,6 @@ int main()
m2 = cmap_str_clone(map);
c_forpair (name, number, cmap_str, m2)
- printf("%s: %" PRIdMAX "\n", cstr_str(&_.name), *_.number);
+ printf("%s: %" PRIdMAX "\n", cstr_str(_.name), **_.number);
}
}
diff --git a/examples/sso_map.c b/examples/sso_map.c
index d6174da8..bab182e3 100644
--- a/examples/sso_map.c
+++ b/examples/sso_map.c
@@ -12,7 +12,7 @@ int main()
c_forpair (k, v, cmap_str, m)
printf("%s: '%s' Len=%" PRIuMAX ", Is long: %s\n",
- cstr_str(&_.k), cstr_str(&_.v), cstr_size(_.v),
- cstr_is_long(&_.v)?"true":"false");
+ cstr_str(_.k), cstr_str(_.v), cstr_size(*_.v),
+ cstr_is_long(_.v)?"true":"false");
}
}
diff --git a/examples/vikings.c b/examples/vikings.c
index 41f5eb5b..623cd172 100644
--- a/examples/vikings.c
+++ b/examples/vikings.c
@@ -65,8 +65,8 @@ int main()
v->second += 3; // add 3 hp points to Einar
Vikings_emplace(&vikings, einar, 0).ref->second += 5; // add 5 more to Einar
- c_forpair (viking, hp, Vikings, vikings) {
- printf("%s of %s has %d hp\n", cstr_str(&_.viking.name), cstr_str(&_.viking.country), _.hp);
+ c_forpair (vik, hp, Vikings, vikings) {
+ printf("%s of %s has %d hp\n", cstr_str(&_.vik->name), cstr_str(&_.vik->country), *_.hp);
}
}
}
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index b6023f4b..ffdd0215 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -162,9 +162,9 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle,
; it.ref != it##_end_.ref; C##_next(&it))
#define c_forpair(key, val, C, cnt) /* structured binding */ \
- for (struct {C##_iter _it; C##_value* _endref; C##_key key; C##_mapped val;} \
+ for (struct {C##_iter _it; C##_value* _endref; const C##_key* key; C##_mapped* val;} \
_ = {C##_begin(&cnt), C##_end(&cnt).ref} \
- ; _._it.ref != _._endref && (_.key = _._it.ref->first, _.val = _._it.ref->second, true) \
+ ; _._it.ref != _._endref && (_.key = &_._it.ref->first, _.val = &_._it.ref->second) \
; C##_next(&_._it))
#define c_forrange(...) c_MACRO_OVERLOAD(c_forrange, __VA_ARGS__)