From 3be928828630984f4ff2c5cf352ace1366c52341 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 24 Sep 2020 16:58:37 +0200 Subject: Changed iter.get to iter.val member. Internal, but used external. Will not change again. --- examples/shared_ptr.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'examples/shared_ptr.c') diff --git a/examples/shared_ptr.c b/examples/shared_ptr.c index 40f67e11..7bff502c 100644 --- a/examples/shared_ptr.c +++ b/examples/shared_ptr.c @@ -5,16 +5,26 @@ typedef struct { cstr_t name, last; } Person; +Person* Person_make(Person* p, const char* name, const char* last) { + p->name = cstr(name), p->last = cstr(last); + return p; +} void Person_del(Person* p) { printf("del %s\n", p->name.str); - cstr_del(&p->name); cstr_del(&p->last); + c_del(cstr, &p->name, &p->last); +} +int Person_compare(const Person* p, const Person* q) { + int cmp = cstr_equals_s(p->name, q->name); + return cmp == 0 ? cstr_equals_s(p->last, q->last) : cmp; } //using_clist(p, Person, Person_del); //using_cqueue(p, clist_p); using_csptr(p, Person, Person_del); -using_clist(pp, csptr_p, csptr_p_del); +int csptr_p_compare(const csptr_p* p, const csptr_p* q) {return Person_compare(p->get, q->get);} + +using_clist(pp, csptr_p, csptr_p_del, csptr_p_compare); using_cqueue(pp, clist_pp); int main() { @@ -32,7 +42,7 @@ int main() { cqueue_pp_pop(&queue); c_foreach (i, cqueue_pp, queue) - printf(" %s %s\n", i.get->get->name.str, i.get->get->last.str); + printf(" %s %s\n", i.val->get->name.str, i.val->get->last.str); cqueue_pp_del(&queue); } \ No newline at end of file -- cgit v1.2.3