summaryrefslogtreecommitdiffhomepage
path: root/examples/csset_erase.c
blob: 96bc4c981c47579697d7e628686a0986c8749b2f (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
#include <stc/csset.h>
#include <stdio.h>

using_csset(i, int);

int main()
{
    c_init(csset_i, set, {30, 20, 80, 40, 60, 90, 10, 70, 50});
    c_foreach (k, csset_i, set) printf(" %d", *k.ref); puts("");

    int val = 64;
    csset_i_iter_t it;
    printf("Show values >= %d:\n", val);
    it = csset_i_lower_bound(&set, val);
    c_foreach (k, csset_i, it, csset_i_end(&set)) printf(" %d", *k.ref); puts("");

    printf("Erase values >= %d:\n", val);
    while (it.ref) it = csset_i_erase_it(&set, it);
    c_foreach (k, csset_i, set) printf(" %d", *k.ref); puts("");

    val = 35;
    printf("Erase values < %d:\n", val);
    it = csset_i_lower_bound(&set, val);
    csset_i_erase_range(&set, csset_i_begin(&set), it);
    c_foreach (k, csset_i, set) printf(" %d", *k.ref); puts("");

    csset_i_del(&set);
}