diff options
| author | realtradam <[email protected]> | 2023-04-12 15:55:33 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2023-04-12 15:55:33 -0400 |
| commit | 0841165881871ee01b782129be681209aeed2423 (patch) | |
| tree | 8a76b61dcaab381b6b42305201ae8b6259f6b6c0 /misc/examples/new_list.c | |
| parent | 554f3e8acf7855b5d6a90cc68cefb7445460b03c (diff) | |
| parent | 0516aa3ae823ed9a22b2c5f776948c8447c32c31 (diff) | |
| download | STC-modified-0841165881871ee01b782129be681209aeed2423.tar.gz STC-modified-0841165881871ee01b782129be681209aeed2423.zip | |
Merge branch 'master' into modified
Diffstat (limited to 'misc/examples/new_list.c')
| -rw-r--r-- | misc/examples/new_list.c | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/misc/examples/new_list.c b/misc/examples/new_list.c index 6dbe80b4..8b291d34 100644 --- a/misc/examples/new_list.c +++ b/misc/examples/new_list.c @@ -1,20 +1,20 @@ -#include <stc/cstr.h> +#include <stdio.h> +#include <stc/forward.h> forward_clist(clist_i32, int); forward_clist(clist_pnt, struct Point); -struct MyStruct { +typedef struct { clist_i32 intlst; clist_pnt pntlst; -} typedef MyStruct; +} MyStruct; #define i_val int -#define i_opt c_is_forward #define i_tag i32 -#define i_extern // define _clist_mergesort() +#define i_is_forward #include <stc/clist.h> -struct Point { int x, y; } typedef Point; +typedef struct Point { int x, y; } Point; int point_cmp(const Point* a, const Point* b) { int c = a->x - b->x; return c ? c : a->y - b->y; @@ -22,40 +22,47 @@ int point_cmp(const Point* a, const Point* b) { #define i_val Point #define i_cmp point_cmp -#define i_opt c_is_forward +#define i_is_forward #define i_tag pnt #include <stc/clist.h> #define i_val float #include <stc/clist.h> -#define i_val_str +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 #include <stc/clist.h> +void MyStruct_drop(MyStruct* s) { + clist_i32_drop(&s->intlst); + clist_pnt_drop(&s->pntlst); +} + int main() { - c_auto (clist_i32, lst) - clist_i32_push_back(&lst, 123); + MyStruct my = {0}; + clist_i32_push_back(&my.intlst, 123); + clist_pnt_push_back(&my.pntlst, (Point){123, 456}); + MyStruct_drop(&my); + + clist_pnt plst = c_make(clist_pnt, {{42, 14}, {32, 94}, {62, 81}}); + clist_pnt_sort(&plst); - c_auto (clist_pnt, plst) { - c_forlist (i, Point, {{42, 14}, {32, 94}, {62, 81}}) - clist_pnt_push_back(&plst, *i.ref); + c_foreach (i, clist_pnt, plst) + printf(" (%d %d)", i.ref->x, i.ref->y); + puts(""); + clist_pnt_drop(&plst); - clist_pnt_sort(&plst); - c_foreach (i, clist_pnt, plst) - printf(" (%d %d)", i.ref->x, i.ref->y); - puts(""); - } + clist_float flst = c_make(clist_float, {123.3f, 321.2f, -32.2f, 78.2f}); + clist_float_sort(&flst); - c_auto (clist_float, flst) { - c_forlist (i, float, {123.3f, 321.2f, -32.2f, 78.2f}) - clist_float_push_back(&flst, *i.ref); - - c_foreach (i, clist_float, flst) printf(" %g", *i.ref); - } + c_foreach (i, clist_float, flst) + printf(" %g", *i.ref); - c_auto (clist_str, slst) - clist_str_emplace_back(&slst, "Hello, friend"); + puts(""); + clist_float_drop(&flst); } |
