summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/mapmap.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-12-30 19:26:51 +0100
committerGitHub <[email protected]>2022-12-30 19:26:51 +0100
commit9d59845f622fbb9c225bbe32246a3128ad9ec0b1 (patch)
tree528ebcc735cdb5d958b987c886d369bc02a11320 /misc/examples/mapmap.c
parent5f57d597cd27aef55adbcb3b452973b0c6e33667 (diff)
parente124d8c7377de1dfce45790a196312596f6b9be5 (diff)
downloadSTC-modified-9d59845f622fbb9c225bbe32246a3128ad9ec0b1.tar.gz
STC-modified-9d59845f622fbb9c225bbe32246a3128ad9ec0b1.zip
Merge pull request #41 from tylov/allcaps
Allcaps
Diffstat (limited to 'misc/examples/mapmap.c')
-rw-r--r--misc/examples/mapmap.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/misc/examples/mapmap.c b/misc/examples/mapmap.c
index 488cc539..d5fe9c81 100644
--- a/misc/examples/mapmap.c
+++ b/misc/examples/mapmap.c
@@ -4,18 +4,24 @@
// People: std::map<std::string, std::string>
#define i_type People
-#define i_key_str
-#define i_val_str
+#define i_key_str // name
+#define i_val_str // email
#define i_keydrop(p) (printf("kdrop: %s\n", cstr_str(p)), cstr_drop(p)) // override
#include <stc/csmap.h>
// Departments: std::map<std::string, People>
#define i_type Departments
-#define i_key_str
+#define i_key_str // dep. name
#define i_valclass People
-// Shorthand for:
+// i_key_str implies:
+// #define i_tag str
+// #define i_key cstr
+// #define i_keyclone cstr_clone
+// #define i_keydrop cstr_drop
+// #define i_cmp cstr_cmp
+// #define i_hash cstr_hash
+// i_valclass implies:
// #define i_val People
-// #define i_cmp People_cmp
// #define i_valclone People_clone
// #define i_valdrop People_drop
#include <stc/csmap.h>
@@ -23,14 +29,14 @@
void add(Departments* deps, const char* name, const char* email, const char* dep)
{
- People *people = &Departments_insert(deps, cstr_from(dep), People_init()).ref->second;
+ People *people = &Departments_emplace(deps, dep, People_init()).ref->second;
People_emplace_or_assign(people, name, email);
}
int contains(Departments* map, const char* name)
{
int count = 0;
- c_foreach (i, Departments, *map)
+ c_FOREACH (i, Departments, *map)
if (People_contains(&i.ref->second, name))
++count;
return count;
@@ -38,7 +44,7 @@ int contains(Departments* map, const char* name)
int main(void)
{
- c_auto (Departments, map)
+ c_AUTO (Departments, map)
{
add(&map, "Anna Kendro", "[email protected]", "Support");
add(&map, "Terry Dane", "[email protected]", "Development");
@@ -54,8 +60,8 @@ int main(void)
add(&map, "Dennis Kay", "[email protected]", "Marketing");
add(&map, "Anne Dickens", "[email protected]", "Development");
- c_foreach (i, Departments, map)
- c_forpair (name, email, People, i.ref->second)
+ 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));
puts("");