From e4c1dadb85e08d88fbc706e49a5d2b18b39fe0ed Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 3 Jan 2021 10:50:41 +0100 Subject: Force template argument *clone* to be specified when *del* is specified for containers. Can be *c_no_clone* if clonable is not required. --- examples/complex.c | 4 ++-- examples/inits.c | 2 +- examples/mapmap.c | 2 +- examples/ptr.c | 6 +++--- examples/share_ptr.c | 4 ++-- examples/share_ptr2.c | 30 ------------------------------ 6 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 examples/share_ptr2.c (limited to 'examples') diff --git a/examples/complex.c b/examples/complex.c index 6f665208..16aa75b7 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -5,8 +5,8 @@ void check_del(float* v) {printf("destroy %g\n", *v);} -using_carray(f, float, check_del, c_default_clone); // normally omit the last argument - float type need no destroy. -using_clist(a, carray2f, c_no_compare, carray2f_del); +using_carray(f, float, check_del, c_default_clone); // normally omit the last 2 arguments - float type need no destroy. +using_clist(a, carray2f, c_no_compare, carray2f_del, carray2f_clone); using_cmap(l, int, clist_a, clist_a_del, clist_a_clone); using_cmap_strkey(s, cmap_l, cmap_l_del, cmap_l_clone); diff --git a/examples/inits.c b/examples/inits.c index 59ed0ad2..320e5b9a 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -5,7 +5,7 @@ #include #include -using_cmap(id, int, cstr, cstr_del); // Map of int -> cstr +using_cmap(id, int, cstr, cstr_del, cstr_clone); // Map of int -> cstr using_cmap_strkey(cnt, int); typedef struct {int x, y;} ipair_t; diff --git a/examples/mapmap.c b/examples/mapmap.c index 1128387d..a56a30db 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -4,7 +4,7 @@ #include using_cmap_str(); -using_cmap_strkey(cfg, cmap_str, cmap_str_del); +using_cmap_strkey(cfg, cmap_str, cmap_str_del, cmap_str_clone); int main(void) { cmap_cfg config = cmap_inits; diff --git a/examples/ptr.c b/examples/ptr.c index 37138952..a7b18ad5 100644 --- a/examples/ptr.c +++ b/examples/ptr.c @@ -23,15 +23,15 @@ Person Person_clone(Person p) { } // 1. cvec of Person struct -using_cvec(pe, Person, Person_compare, Person_del); +using_cvec(pe, Person, Person_compare, Person_del, Person_clone); // 2. cvec of raw/owned pointers to Person -using_cptr(pe, Person, Person_compare, Person_del); +using_cptr(pe, Person, Person_compare, Person_del, Person_clone); using_cvec(pp, Person*, cptr_pe_compare, cptr_pe_del, cptr_pe_clone); // 3. cvec of shared-ptr to Person using_csptr(pe, Person, Person_compare, Person_del); -using_cvec(ps, csptr_pe, csptr_pe_compare, csptr_pe_del); +using_cvec(ps, csptr_pe, csptr_pe_compare, csptr_pe_del, csptr_pe_clone); const char* names[] = { "Joe", "Jordan", diff --git a/examples/share_ptr.c b/examples/share_ptr.c index 18739d29..9387bd61 100644 --- a/examples/share_ptr.c +++ b/examples/share_ptr.c @@ -20,8 +20,8 @@ int Person_compare(const Person* p, const Person* q) { } using_csptr(pe, Person, Person_compare, Person_del); -using_clist(pe, csptr_pe, csptr_pe_compare, csptr_pe_del); -using_cvec(pe, csptr_pe, csptr_pe_compare, csptr_pe_del); +using_clist(pe, csptr_pe, csptr_pe_compare, csptr_pe_del, csptr_pe_clone); +using_cvec(pe, csptr_pe, csptr_pe_compare, csptr_pe_del, csptr_pe_clone); int main() { clist_pe queue = clist_pe_init(); 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 -#include -#include -#include - -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 -- cgit v1.2.3