summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/new_vec.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples/new_vec.c')
-rw-r--r--misc/examples/new_vec.c52
1 files changed, 18 insertions, 34 deletions
diff --git a/misc/examples/new_vec.c b/misc/examples/new_vec.c
index 84e4c7b2..df443b7f 100644
--- a/misc/examples/new_vec.c
+++ b/misc/examples/new_vec.c
@@ -1,4 +1,4 @@
-#include <stc/cstr.h>
+#include <stdio.h>
#include <stc/forward.h>
forward_cvec(cvec_i32, int);
@@ -10,49 +10,33 @@ struct MyStruct {
} typedef MyStruct;
#define i_val int
-#define i_opt c_is_forward
+#define i_is_forward
#define i_tag i32
#include <stc/cvec.h>
-struct Point { int x, y; } typedef Point;
-int point_cmp(const Point* a, const Point* b) {
- int c = c_default_cmp(&a->x, &b->x);
- return c ? c : c_default_cmp(&a->y, &b->y);
-}
+typedef struct Point { int x, y; } Point;
#define i_val Point
-//#define i_cmp point_cmp
#define i_less(a, b) a->x < b->x || (a->x == b->x && a->y < b->y)
-#define i_opt c_is_forward
+#define i_is_forward
#define i_tag pnt
#include <stc/cvec.h>
-#define i_val float
-#include <stc/cvec.h>
+int main()
+{
+ MyStruct my = {0};
-#define i_val_str
-#include <stc/cvec.h>
+ cvec_pnt_push(&my.pntvec, (Point){42, 14});
+ cvec_pnt_push(&my.pntvec, (Point){32, 94});
+ cvec_pnt_push(&my.pntvec, (Point){62, 81});
+ cvec_pnt_push(&my.pntvec, (Point){32, 91});
+ cvec_pnt_sort(&my.pntvec);
-int main()
-{
- c_auto (cvec_i32, vec)
- c_auto (cvec_float, fvec)
- c_auto (cvec_pnt, pvec)
- c_auto (cvec_str, svec)
- {
- cvec_i32_push(&vec, 123);
- cvec_float_push(&fvec, 123.3f);
-
- cvec_pnt_push(&pvec, (Point){42, 14});
- cvec_pnt_push(&pvec, (Point){32, 94});
- cvec_pnt_push(&pvec, (Point){62, 81});
- cvec_pnt_push(&pvec, (Point){32, 91});
- cvec_pnt_sort(&pvec);
- c_foreach (i, cvec_pnt, pvec)
- printf(" (%d %d)", i.ref->x, i.ref->y);
- puts("");
-
- cvec_str_emplace(&svec, "Hello, friend");
- }
+ c_foreach (i, cvec_pnt, my.pntvec)
+ printf(" (%d %d)", i.ref->x, i.ref->y);
+ puts("");
+
+ cvec_i32_drop(&my.intvec);
+ cvec_pnt_drop(&my.pntvec);
}