diff options
| author | tylov <[email protected]> | 2023-07-21 10:49:45 +0200 |
|---|---|---|
| committer | tylov <[email protected]> | 2023-07-21 10:49:45 +0200 |
| commit | dbcc13635402bd466675f4f41e865d02abc6f918 (patch) | |
| tree | 269bbb8e641aaad34b0cca0bbd23c854faa3a960 /misc/examples/smartpointers/map_box.c | |
| parent | 2d67f4040f6eecd41f1b864b43c62823ed75aff0 (diff) | |
| download | STC-modified-dbcc13635402bd466675f4f41e865d02abc6f918.tar.gz STC-modified-dbcc13635402bd466675f4f41e865d02abc6f918.zip | |
NB! Changed some coroutine API for consistency/simplicity: Added full task support.
Diffstat (limited to 'misc/examples/smartpointers/map_box.c')
| -rw-r--r-- | misc/examples/smartpointers/map_box.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/misc/examples/smartpointers/map_box.c b/misc/examples/smartpointers/map_box.c new file mode 100644 index 00000000..f651b302 --- /dev/null +++ b/misc/examples/smartpointers/map_box.c @@ -0,0 +1,34 @@ +#include <stc/ccommon.h> +#include <stdio.h> +#define i_implement +#include <stc/cstr.h> + +#define i_type IBox +#define i_key long +#include <stc/cbox.h> // unique_ptr<long> alike. + +// cmap of cstr => IBox +#define i_type Boxmap +#define i_key_str +#define i_valboxed IBox // i_valboxed: use properties from IBox automatically +#include <stc/cmap.h> + + +int main(void) +{ + Boxmap map = {0}; + + puts("Map cstr => IBox:"); + Boxmap_insert(&map, cstr_from("Test1"), IBox_make(1)); + Boxmap_insert(&map, cstr_from("Test2"), IBox_make(2)); + + // Simpler: emplace() implicitly creates cstr from const char* and IBox from long! + Boxmap_emplace(&map, "Test3", 3); + Boxmap_emplace(&map, "Test4", 4); + + c_forpair (name, number, Boxmap, map) + printf("%s: %ld\n", cstr_str(_.name), *_.number->get); + puts(""); + + Boxmap_drop(&map); +} |
