diff options
| author | Tyge Løvset <[email protected]> | 2023-03-26 00:27:45 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-03-26 00:27:45 +0100 |
| commit | eb85069b669e754836b9d4587ba03d3af1a5e975 (patch) | |
| tree | 45c9a0d3fe40c59a8b33ae8ecd2e7aa78bef6240 /misc/examples/new_smap.c | |
| parent | e8be14dfc894eeac859f0287d4d5b4f4745c0585 (diff) | |
| download | STC-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/new_smap.c')
| -rw-r--r-- | misc/examples/new_smap.c | 59 |
1 files changed, 24 insertions, 35 deletions
diff --git a/misc/examples/new_smap.c b/misc/examples/new_smap.c index 0870ee3d..d85d5c75 100644 --- a/misc/examples/new_smap.c +++ b/misc/examples/new_smap.c @@ -4,15 +4,10 @@ forward_csmap(PMap, struct Point, int); // Use forward declared PMap in struct -struct MyStruct { +typedef struct { PMap pntmap; cstr name; -} typedef MyStruct; - -// int => int map -#define i_key int -#define i_val int -#include <stc/csmap.h> +} MyStruct; // Point => int map struct Point { int x, y; } typedef Point; @@ -42,36 +37,30 @@ int point_cmp(const Point* a, const Point* b) { int main() { - c_auto (csmap_int, imap) { - csmap_int_insert(&imap, 123, 321); - } - - c_auto (PMap, pmap) { - pmap = c_make(PMap, { - {{42, 14}, 1}, - {{32, 94}, 2}, - {{62, 81}, 3}, - }); + PMap pmap = c_make(PMap, { + {{42, 14}, 1}, + {{32, 94}, 2}, + {{62, 81}, 3}, + }); + SMap smap = c_make(SMap, { + {"Hello, friend", "this is the mapped value"}, + {"The brown fox", "jumped"}, + {"This is the time", "for all good things"}, + }); + SSet sset = {0}; - c_forpair (p, i, PMap, pmap) - printf(" (%d,%d: %d)", _.p->x, _.p->y, *_.i); - puts(""); - } + c_forpair (p, i, PMap, pmap) + printf(" (%d,%d: %d)", _.p->x, _.p->y, *_.i); + puts(""); - c_auto (SMap, smap) { - smap = c_make(SMap, { - {"Hello, friend", "this is the mapped value"}, - {"The brown fox", "jumped"}, - {"This is the time", "for all good things"}, - }); + c_forpair (i, j, SMap, smap) + printf(" (%s: %s)\n", cstr_str(_.i), cstr_str(_.j)); - c_forpair (i, j, SMap, smap) - printf(" (%s: %s)\n", cstr_str(_.i), cstr_str(_.j)); - } + SSet_emplace(&sset, "Hello, friend"); + SSet_emplace(&sset, "Goodbye, foe"); + printf("Found? %s\n", SSet_contains(&sset, "Hello, friend") ? "true" : "false"); - c_auto (SSet, sset) { - SSet_emplace(&sset, "Hello, friend"); - SSet_emplace(&sset, "Goodbye, foe"); - printf("Found? %s\n", SSet_contains(&sset, "Hello, friend") ? "true" : "false"); - } + PMap_drop(&pmap); + SMap_drop(&smap); + SSet_drop(&sset); } |
