summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/hashmap.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-03-26 00:27:45 +0100
committerTyge Løvset <[email protected]>2023-03-26 00:27:45 +0100
commiteb85069b669e754836b9d4587ba03d3af1a5e975 (patch)
tree45c9a0d3fe40c59a8b33ae8ecd2e7aa78bef6240 /misc/examples/hashmap.c
parente8be14dfc894eeac859f0287d4d5b4f4745c0585 (diff)
downloadSTC-modified-eb85069b669e754836b9d4587ba03d3af1a5e975.tar.gz
STC-modified-eb85069b669e754836b9d4587ba03d3af1a5e975.zip
development branch for 4.2
Removed uses of c_auto and c_with in documentation examples and code examples. Still using c_defer a few places. Renamed c11/fmt.h to c11/print.h. Some additions in ccommon.h, e.g. c_const_cast(T, x). Improved docs.
Diffstat (limited to 'misc/examples/hashmap.c')
-rw-r--r--misc/examples/hashmap.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/misc/examples/hashmap.c b/misc/examples/hashmap.c
index f59ed824..47a3bcff 100644
--- a/misc/examples/hashmap.c
+++ b/misc/examples/hashmap.c
@@ -17,32 +17,33 @@ const char* call(const char* number) {
}
int main(void) {
- c_auto (cmap_str, contacts)
- {
- cmap_str_emplace(&contacts, "Daniel", "798-1364");
- cmap_str_emplace(&contacts, "Ashley", "645-7689");
- cmap_str_emplace(&contacts, "Katie", "435-8291");
- cmap_str_emplace(&contacts, "Robert", "956-1745");
-
- const cmap_str_value* v;
- if ((v = cmap_str_get(&contacts, "Daniel")))
- printf("Calling Daniel: %s\n", call(cstr_str(&v->second)));
- else
- printf("Don't have Daniel's number.");
-
- cmap_str_emplace_or_assign(&contacts, "Daniel", "164-6743");
-
- if ((v = cmap_str_get(&contacts, "Ashley")))
- printf("Calling Ashley: %s\n", call(cstr_str(&v->second)));
- else
- printf("Don't have Ashley's number.");
-
- cmap_str_erase(&contacts, "Ashley");
-
- puts("");
- c_forpair (contact, number, cmap_str, contacts) {
- printf("Calling %s: %s\n", cstr_str(_.contact), call(cstr_str(_.number)));
- }
- puts("");
+ cmap_str contacts = {0};
+
+ cmap_str_emplace(&contacts, "Daniel", "798-1364");
+ cmap_str_emplace(&contacts, "Ashley", "645-7689");
+ cmap_str_emplace(&contacts, "Katie", "435-8291");
+ cmap_str_emplace(&contacts, "Robert", "956-1745");
+
+ const cmap_str_value* v;
+ if ((v = cmap_str_get(&contacts, "Daniel")))
+ printf("Calling Daniel: %s\n", call(cstr_str(&v->second)));
+ else
+ printf("Don't have Daniel's number.");
+
+ cmap_str_emplace_or_assign(&contacts, "Daniel", "164-6743");
+
+ if ((v = cmap_str_get(&contacts, "Ashley")))
+ printf("Calling Ashley: %s\n", call(cstr_str(&v->second)));
+ else
+ printf("Don't have Ashley's number.");
+
+ cmap_str_erase(&contacts, "Ashley");
+
+ puts("");
+ c_forpair (contact, number, cmap_str, contacts) {
+ printf("Calling %s: %s\n", cstr_str(_.contact), call(cstr_str(_.number)));
}
+ puts("");
+
+ cmap_str_drop(&contacts);
}