# HG changeset patch # User Mike Becker # Date 1668957663 -3600 # Node ID 5e58187ac707d3c35cdf3f1bc596323db0aba654 # Parent 1f5a8f6f3015b24713f281be79a8b8d83bc31d39 #219 array list: implement insert via iterator diff -r 1f5a8f6f3015 -r 5e58187ac707 src/array_list.c --- a/src/array_list.c Sun Nov 20 15:51:02 2022 +0100 +++ b/src/array_list.c Sun Nov 20 16:21:03 2022 +0100 @@ -183,7 +183,23 @@ void const *elem, int prepend ) { - return 1; + struct cx_list_s *list = iter->src_handle; + if (iter->index < list->size) { + int result = cx_arl_insert( + list, + iter->index + 1 - prepend, + elem + ); + if (result == 0 && prepend != 0) { + iter->index++; + iter->elem_handle = ((char *) iter->elem_handle) + list->itemsize; + } + return result; + } else { + int result = cx_arl_add(list, elem); + iter->index = list->size; + return result; + } } static int cx_arl_remove( diff -r 1f5a8f6f3015 -r 5e58187ac707 test/test_list.cpp --- a/test/test_list.cpp Sun Nov 20 15:51:02 2022 +0100 +++ b/test/test_list.cpp Sun Nov 20 16:21:03 2022 +0100 @@ -917,7 +917,6 @@ } TEST_F(ArrayList, InsertViaIterator) { - ASSERT_EQ(1,0); // TODO: remove when implemented int fivenums[] = {0, 1, 2, 3, 4, 5}; CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4)); // TODO: replace with cxListAddArray