summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/new_list.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples/new_list.c')
-rw-r--r--misc/examples/new_list.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/misc/examples/new_list.c b/misc/examples/new_list.c
index 8b291d34..9676e7b4 100644
--- a/misc/examples/new_list.c
+++ b/misc/examples/new_list.c
@@ -5,11 +5,11 @@ forward_clist(clist_i32, int);
forward_clist(clist_pnt, struct Point);
typedef struct {
- clist_i32 intlst;
- clist_pnt pntlst;
+ clist_i32 intlist;
+ clist_pnt pntlist;
} MyStruct;
-#define i_val int
+#define i_key int
#define i_tag i32
#define i_is_forward
#include <stc/clist.h>
@@ -20,49 +20,51 @@ int point_cmp(const Point* a, const Point* b) {
return c ? c : a->y - b->y;
}
-#define i_val Point
+#define i_key Point
#define i_cmp point_cmp
#define i_is_forward
#define i_tag pnt
#include <stc/clist.h>
-#define i_val float
+#define i_key float
+#define i_native_cmp // use < and == operators for comparison
#include <stc/clist.h>
void MyStruct_drop(MyStruct* s);
#define i_type MyList
-#define i_valclass MyStruct // i_valclass uses MyStruct_drop
-#define i_opt c_no_clone|c_no_cmp
+#define i_key MyStruct
+#define i_keydrop MyStruct_drop // define drop function
+#define i_no_clone // must explicitely exclude or define cloning support because of drop.
#include <stc/clist.h>
void MyStruct_drop(MyStruct* s) {
- clist_i32_drop(&s->intlst);
- clist_pnt_drop(&s->pntlst);
+ clist_i32_drop(&s->intlist);
+ clist_pnt_drop(&s->pntlist);
}
-int main()
+int main(void)
{
MyStruct my = {0};
- clist_i32_push_back(&my.intlst, 123);
- clist_pnt_push_back(&my.pntlst, (Point){123, 456});
+ clist_i32_push_back(&my.intlist, 123);
+ clist_pnt_push_back(&my.pntlist, c_LITERAL(Point){123, 456});
MyStruct_drop(&my);
- clist_pnt plst = c_make(clist_pnt, {{42, 14}, {32, 94}, {62, 81}});
- clist_pnt_sort(&plst);
+ clist_pnt plist = c_init(clist_pnt, {{42, 14}, {32, 94}, {62, 81}});
+ clist_pnt_sort(&plist);
- c_foreach (i, clist_pnt, plst)
+ c_foreach (i, clist_pnt, plist)
printf(" (%d %d)", i.ref->x, i.ref->y);
puts("");
- clist_pnt_drop(&plst);
+ clist_pnt_drop(&plist);
- clist_float flst = c_make(clist_float, {123.3f, 321.2f, -32.2f, 78.2f});
- clist_float_sort(&flst);
+ clist_float flist = c_init(clist_float, {123.3f, 321.2f, -32.2f, 78.2f});
+ clist_float_sort(&flist);
- c_foreach (i, clist_float, flst)
- printf(" %g", *i.ref);
+ c_foreach (i, clist_float, flist)
+ printf(" %g", (double)*i.ref);
puts("");
- clist_float_drop(&flst);
+ clist_float_drop(&flist);
}