summaryrefslogtreecommitdiffhomepage
path: root/examples/share_ptr2.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-01-03 10:50:41 +0100
committerTyge Løvset <[email protected]>2021-01-03 10:50:41 +0100
commite4c1dadb85e08d88fbc706e49a5d2b18b39fe0ed (patch)
tree731d91462d450fb848dd9125efdc8dc77c68d730 /examples/share_ptr2.c
parent949c6b61cae7bb4665f47a6f27375dd450a23854 (diff)
downloadSTC-modified-e4c1dadb85e08d88fbc706e49a5d2b18b39fe0ed.tar.gz
STC-modified-e4c1dadb85e08d88fbc706e49a5d2b18b39fe0ed.zip
Force template argument *clone* to be specified when *del* is specified for containers. Can be *c_no_clone* if clonable is not required.
Diffstat (limited to 'examples/share_ptr2.c')
-rw-r--r--examples/share_ptr2.c30
1 files changed, 0 insertions, 30 deletions
diff --git a/examples/share_ptr2.c b/examples/share_ptr2.c
deleted file mode 100644
index 34abcd74..00000000
--- a/examples/share_ptr2.c
+++ /dev/null
@@ -1,30 +0,0 @@
-#include <stc/cptr.h>
-#include <stc/cmap.h>
-#include <stc/cstr.h>
-#include <stdio.h>
-
-typedef struct { cstr_t name, last; } Person;
-
-Person* Person_from(Person* p, cstr_t name, cstr_t last) {
- p->name = name, p->last = last;
- return p;
-}
-void Person_del(Person* p) {
- c_del(cstr, &p->name, &p->last);
-}
-
-using_csptr(ps, Person, c_no_compare, Person_del);
-using_cmap(ps, int, csptr_ps, csptr_ps_del);
-
-
-int main() {
- cmap_ps map = cmap_ps_init();
- c_forrange (i, 20) {
- c_try_emplace(&map, cmap_ps, (i * 7) % 10,
- csptr_ps_from(Person_from(c_new(Person), cstr_from_fmt("Name %d", (i * 7) % 10),
- cstr_from_fmt("Last %d", (i * 9) % 10))));
- }
- c_foreach (i, cmap_ps, map)
- printf(" %d: %s\n", i.ref->first, i.ref->second.get->name.str);
- cmap_ps_del(&map);
-} \ No newline at end of file