diff -r fb82e7a92258 -r 81c301a59b7c docs/Writerside/topics/list.h.md --- a/docs/Writerside/topics/list.h.md Mon Oct 20 19:44:18 2025 +0200 +++ b/docs/Writerside/topics/list.h.md Mon Oct 20 20:10:36 2025 +0200 @@ -120,6 +120,10 @@ void *cxListEmplaceAt(CxList *list, size_t index); +CxIterator cxListEmplaceArray(CxList *list, size_t n); + +CxIterator cxListEmplaceArrayAt(CxList *list, size_t index, size_t n); + int cxListInsertSorted(CxList *list, const void *elem); int cxListInsertUnique(CxList *list, const void *elem); @@ -145,8 +149,15 @@ The functions `cxListEmplace()` and `cxListEmplaceAt()` behave like `cxListAdd()` and `cxListInsert()`, except that they only allocate the memory and return a pointer to it, leaving it to the callee to copy the element data into it. +The same is true for `cxListEmplaceArray()` and `cxListEmplaceArrayAt()`, which allocate memory for `n` elements and return an iterator to the first element. Be aware that when the list is storing pointers, the allocated memory will be for the pointer, not the actual element's data. +> If `cxListEmplaceArray()` or `cxListEmplaceArrayAt()` is unable to allocate memory for `n` elements, +> the iterator will iterate only over the elements that have been successfully allocated. +> The `elem_count` attribute of the iterator will be set to the number of successfully allocated elements. +> And the `index` attribute will count from zero to `elem_count - 1`. +> {style="note"} + The function `cxListInsertSorted()` inserts the element at the correct position so that the list remains sorted according to the list's compare function. It is important that the list is already sorted before calling this function. On the other hand, `cxListInsertUnique()` inserts the element only if it is not already in the list. @@ -418,8 +429,8 @@ |------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `clear` | Invoke destructor functions on all elements and remove them from the list. | | `deallocate` | Invoke destructor functions on all elements and deallocate the entire list memory. | -| `insert_element` | Insert a single element at the specified index. Return a pointer to the allocated element or `NULL` on failure. | -| `insert_array` | Insert an array of elements starting at the specified index. Return the number of elements inserted. | +| `insert_element` | Insert or allocate a single element at the specified index. Return a pointer to the allocated element or `NULL` on failure. | +| `insert_array` | Insert or allocate an array of elements starting at the specified index. Return the number of successfully inserted or allocated elements. | | `insert_sorted` | Insert an array of sorted elements into a sorted list. Return the number of elements processed (equals the number of elements inserted in this case). | | `insert_unique` | Insert an array of sorted unique elements into a sorted list. Return the number of elements processed (not the number of elements inserted, which might be lower). | | `insert_iter` | Insert a single element depending on the iterator position. The third argument to this function is zero when the element shall be inserted after the iterator position and non-zero if it shall be inserted before the iterator position. The implementation is also responsible for adjusting the iterator, respectively. |