diff options
| author | Tyge Lovset <[email protected]> | 2022-12-20 23:31:51 +0100 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-12-20 23:31:51 +0100 |
| commit | 5f57d597cd27aef55adbcb3b452973b0c6e33667 (patch) | |
| tree | dfd59c2fd0e36a6ef37912a9d0cc5a65970f1524 /misc/examples/list_erase.c | |
| parent | 1763be8c8cbbc0896477fcf924edd4180d1345a9 (diff) | |
| download | STC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.tar.gz STC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.zip | |
Restructured folders: examples, benchmarks, tests into misc folder.
Diffstat (limited to 'misc/examples/list_erase.c')
| -rw-r--r-- | misc/examples/list_erase.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/misc/examples/list_erase.c b/misc/examples/list_erase.c new file mode 100644 index 00000000..c1a2aa97 --- /dev/null +++ b/misc/examples/list_erase.c @@ -0,0 +1,32 @@ +// erasing from clist +#include <stdio.h> + +#define i_type IList +#define i_val int +#include <stc/clist.h> + +int main () +{ + c_with (IList L = IList_init(), IList_drop(&L)) + { + c_forlist (i, int, {10, 20, 30, 40, 50}) + IList_push(&L, *i.ref); + + 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(""); + } +} |
