From c67a87749fb02c32e982dd309f62b54c1efde076 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 22 Apr 2021 15:18:29 +0200 Subject: clist_X_splice*() now returns updated input iter. Added list_splice.c example. --- examples/list_splice.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 examples/list_splice.c (limited to 'examples') diff --git a/examples/list_splice.c b/examples/list_splice.c new file mode 100644 index 00000000..06464c27 --- /dev/null +++ b/examples/list_splice.c @@ -0,0 +1,34 @@ +#include +#include + +using_clist(i, int); + +void print_ilist(const char* s, clist_i list) +{ + printf("%s", s); + c_foreach (i, clist_i, list) { + printf(" %d", *i.ref); + } + puts(""); +} + +int main () +{ + c_init (clist_i, list1, { 1, 2, 3, 4, 5 }); + c_init (clist_i, list2, { 10, 20, 30, 40, 50 }); + + clist_i_iter_t it = clist_i_fwd(clist_i_begin(&list1), 2); + it = clist_i_splice(&list1, it, &list2); + + puts("After splice"); + print_ilist("list1:", list1); + print_ilist("list2:", list2); + + clist_i_splice_range(&list2, clist_i_begin(&list2), &list1, it, clist_i_end(&list1)); + + puts("After splice_range"); + print_ilist("list1:", list1); + print_ilist("list2:", list2); + + c_del(clist_i, &list1, &list2); +} \ No newline at end of file -- cgit v1.2.3