114 |
114 |
115 int cxListAdd(CxList *list, const void *elem); |
115 int cxListAdd(CxList *list, const void *elem); |
116 |
116 |
117 int cxListInsert(CxList *list, size_t index, const void *elem); |
117 int cxListInsert(CxList *list, size_t index, const void *elem); |
118 |
118 |
|
119 void *cxListEmplace(CxList *list); |
|
120 |
|
121 void *cxListEmplaceAt(CxList *list, size_t index); |
|
122 |
119 int cxListInsertSorted(CxList *list, const void *elem); |
123 int cxListInsertSorted(CxList *list, const void *elem); |
120 |
124 |
121 size_t cxListAddArray(CxList *list, const void *array, size_t n); |
125 size_t cxListAddArray(CxList *list, const void *array, size_t n); |
122 |
126 |
123 size_t cxListInsertArray(CxList *list, size_t index, |
127 size_t cxListInsertArray(CxList *list, size_t index, |
130 |
134 |
131 int cxListInsertBefore(CxIterator *iter, const void *elem); |
135 int cxListInsertBefore(CxIterator *iter, const void *elem); |
132 ``` |
136 ``` |
133 |
137 |
134 The function `cxListAdd()` appends the element `elem` to the list and returns zero on success or non-zero when allocating the memory for the element fails. |
138 The function `cxListAdd()` appends the element `elem` to the list and returns zero on success or non-zero when allocating the memory for the element fails. |
135 Similarly, `cxListInsert()` adds the element at the specified `index`, |
139 Similarly, `cxListInsert()` adds the element at the specified `index`. |
136 and `cxListInsertSorted()` adds the element at the correct position so that the list remains sorted according to the list's compare function. |
140 |
|
141 The functions `cxListEmplace()` and `cxListEmplaceAt()` behave like `cxListAdd()` and `cxListInsert()`, |
|
142 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. |
|
143 Be aware that when the list is storing pointers, the allocated memory will be for the pointer, not the actual element's data. |
|
144 |
|
145 The function `cxListInsertSorted()` inserts the element at the correct position so that the list remains sorted according to the list's compare function. |
137 |
146 |
138 When you are currently iterating through a list, you can insert elements before or after the current position of the iterator |
147 When you are currently iterating through a list, you can insert elements before or after the current position of the iterator |
139 with `cxListInsertBefore()` or `cxListInsertAfter()`, respectively. |
148 with `cxListInsertBefore()` or `cxListInsertAfter()`, respectively. |
140 This _should_ be done with [mutating iterators](iterator.h.md#mutating-iterators) only, but is also defined for normal iterators. |
149 This _should_ be done with [mutating iterators](iterator.h.md#mutating-iterators) only, but is also defined for normal iterators. |
141 |
150 |
403 |
412 |
404 | Function | Description | |
413 | Function | Description | |
405 |------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
414 |------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
406 | `clear` | Invoke destructor functions on all elements and remove them from the list. | |
415 | `clear` | Invoke destructor functions on all elements and remove them from the list. | |
407 | `deallocate` | Invoke destructor functions on all elements and deallocate the entire list memory. | |
416 | `deallocate` | Invoke destructor functions on all elements and deallocate the entire list memory. | |
408 | `insert_element` | Insert a single element at the specified index. Return zero on success and non-zero on failure. | |
417 | `insert_element` | Insert a single element at the specified index. Return a pointer to the data of the inserted element or `NULL` on failure. | |
409 | `insert_array` | Insert an array of elements starting at the specified index. Return the number of elements inserted. | |
418 | `insert_array` | Insert an array of elements starting at the specified index. Return the number of elements inserted. | |
410 | `insert_sorted` | Insert an array of sorted elements into a sorted list. Return the number of elements inserted. | |
419 | `insert_sorted` | Insert an array of sorted elements into a sorted list. Return the number of elements inserted. | |
411 | `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. | |
420 | `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. | |
412 | `remove` | Removes a multiple elements starting at the specified index. If a target buffer is specified, copy the elements to that buffer. Otherwise, invoke the destructor functions for the elements. Return the number of elements actually removed. | |
421 | `remove` | Removes a multiple elements starting at the specified index. If a target buffer is specified, copy the elements to that buffer. Otherwise, invoke the destructor functions for the elements. Return the number of elements actually removed. | |
413 | `swap` | Swap two elements by index. Return zero on success or non-zero when any index was out-of-bounds. | |
422 | `swap` | Swap two elements by index. Return zero on success or non-zero when any index was out-of-bounds. | |