367 size_t cxListClone(CxList *dst, const CxList *src, |
367 size_t cxListClone(CxList *dst, const CxList *src, |
368 cx_clone_func clone_func, |
368 cx_clone_func clone_func, |
369 const CxAllocator *clone_allocator, |
369 const CxAllocator *clone_allocator, |
370 void *data); |
370 void *data); |
371 ``` |
371 ``` |
|
372 |
|
373 With `cxListClone()` you can create deep copies of the elements in a list and insert them into another list. |
|
374 The destination list does not need to be empty, in which case the elements will be appended. |
|
375 Depending on the concrete list implementation, `cxListClone()` tries to allocate enough memory up-front, before trying |
|
376 to insert anything. |
|
377 |
|
378 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it. |
|
379 |
|
380 The function returns the number of elements successfully cloned. |
|
381 If an allocation error occurs, this might be smaller than the size of the source list. |
|
382 |
|
383 > It is perfectly possible to clone items into a list of a different type. |
|
384 > For example, you can clone elements from a list that is just storing pointers (`CX_STORE_POINTERS`) to a list that |
|
385 > allocates the memory for the objects (and vice versa). |
372 |
386 |
373 ## Dispose |
387 ## Dispose |
374 |
388 |
375 ```C |
389 ```C |
376 #include <cx/list.h> |
390 #include <cx/list.h> |