summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/list_erase.c
blob: 47f56625549c1adf77fa06a559954a4abb65c9b6 (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
// erasing from clist
#include <stdio.h>

#define i_type IList
#define i_val int
#include <stc/clist.h>

int main ()
{
    c_with (IList L = c_make(IList, {10, 20, 30, 40, 50}), IList_drop(&L))
    {
        c_foreach (x, IList, L)
            printf("%d ", *x.ref);
        puts("");
                                              // 10 20 30 40 50
        IList_iter it = IList_begin(&L);      // ^
        IList_next(&it);
        it = IList_erase_at(&L, it);          // 10 30 40 50
                                              //    ^
        IList_iter end = IList_end(&L);       //
        IList_next(&it);
        it = IList_erase_range(&L, it, end);  // 10 30
                                              //       ^
        printf("list contains:");
        c_foreach (x, IList, L)
            printf(" %d", *x.ref);
        puts("");
    }
}