summaryrefslogtreecommitdiffhomepage
path: root/tests/test_new_deq.c
blob: d1a5c2a605dd4535e06759bde7fc7b77dfa46faf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stc/cstr.h>
#include <stc/forward.h>

forward_cdeq(i32, int);
forward_cdeq(pnt, struct Point);

struct MyStruct {
    cdeq_i32 intvec;
    cdeq_pnt pntvec;
} typedef MyStruct;


#define F_tag i32
#define i_val int
#include <stc/cdeq.h>

struct Point { int x, y; } typedef Point;
int point_compare(const Point* a, const Point* b) {
    int c = c_default_compare(&a->x, &b->x);
    return c ? c : c_default_compare(&a->y, &b->y);
}
#define F_tag pnt
#define i_val Point
#define i_cmp point_compare
#include <stc/cdeq.h>

#define i_val float
#include <stc/cdeq.h>

#define i_val_str
#include <stc/cdeq.h>


int main()
{
    cdeq_i32 vec = cdeq_i32_init();
    cdeq_i32_push_back(&vec, 123);
    cdeq_i32_del(&vec);

    cdeq_float fvec = cdeq_float_init();
    cdeq_float_push_back(&fvec, 123.3);
    cdeq_float_del(&fvec);

    cdeq_pnt pvec = cdeq_pnt_init();
    cdeq_pnt_push_back(&pvec, (Point){42, 14});
    cdeq_pnt_push_back(&pvec, (Point){32, 94});
    cdeq_pnt_push_front(&pvec, (Point){62, 81});
    cdeq_pnt_sort(&pvec);
    c_foreach (i, cdeq_pnt, pvec)
        printf(" (%d %d)", i.ref->x, i.ref->y);
    puts("");
    cdeq_pnt_del(&pvec);

    cdeq_str svec = cdeq_str_init();
    cdeq_str_emplace_back(&svec, "Hello, friend");
    cdeq_str_del(&svec);
}