277 Otherwise, the iterator shall yield pointers to the map's memory where the value is stored. |
277 Otherwise, the iterator shall yield pointers to the map's memory where the value is stored. |
278 |
278 |
279 It is always safe to call the above functions on a `NULL`-pointer. |
279 It is always safe to call the above functions on a `NULL`-pointer. |
280 In that case, the returned iterator will behave like an iterator over an empty map. |
280 In that case, the returned iterator will behave like an iterator over an empty map. |
281 |
281 |
|
282 ## Clone |
|
283 |
|
284 ```C |
|
285 #include <cx/allocator.h> |
|
286 |
|
287 typedef void*(cx_clone_func)( |
|
288 void *target, const void *source, |
|
289 const CxAllocator *allocator, |
|
290 void *data); |
|
291 |
|
292 #include <cx/map.h> |
|
293 |
|
294 size_t cxMapClone(CxMap *dst, const CxMap *src, |
|
295 cx_clone_func clone_func, |
|
296 const CxAllocator *clone_allocator, |
|
297 void *data); |
|
298 ``` |
|
299 |
|
300 With `cxMapClone()` you can create deep copies of the values in one map and insert them into another map. |
|
301 The destination map does not need to be empty. |
|
302 But when a key already exists in the destination map, the value is overwritten with the clone from the source map. |
|
303 If the destination map has destructors defined, they are called for the replaced element. |
|
304 |
|
305 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it. |
|
306 |
|
307 The function returns the number of elements successfully cloned. |
|
308 If an allocation error occurs, this might be smaller than the size of the source map. |
|
309 |
|
310 > It is perfectly possible to clone items into a map of a different type. |
|
311 > For example, you can clone entries from a map that is just storing pointers (`CX_STORE_POINTERS`) to a map that |
|
312 > allocates the memory for the objects (and vice versa). |
|
313 |
282 ## Dispose |
314 ## Dispose |
283 |
315 |
284 ```C |
316 ```C |
285 #include <cx/map.h> |
317 #include <cx/map.h> |
286 |
318 |