diff options
| author | Tyge Løvset <[email protected]> | 2020-09-24 16:58:37 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-09-24 16:58:37 +0200 |
| commit | 3be928828630984f4ff2c5cf352ace1366c52341 (patch) | |
| tree | c72decd6ee5d3bcd19013eb56c816759ce908ca8 /examples/shared_ptr.c | |
| parent | bad270ce0034ffbd237bc9ac4a407b0cfe6b1088 (diff) | |
| download | STC-modified-3be928828630984f4ff2c5cf352ace1366c52341.tar.gz STC-modified-3be928828630984f4ff2c5cf352ace1366c52341.zip | |
Changed iter.get to iter.val member. Internal, but used external. Will not change again.
Diffstat (limited to 'examples/shared_ptr.c')
| -rw-r--r-- | examples/shared_ptr.c | 16 |
1 files changed, 13 insertions, 3 deletions
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 |
