docs/Writerside/topics/collection.h.md

changeset 1689
a5b7cf49dea7
parent 1639
5c3e6477aab4
child 1694
a2757c6427cc
equal deleted inserted replaced
1688:27073814f654 1689:a5b7cf49dea7
104 cxSetDestructor(c, destr) 104 cxSetDestructor(c, destr)
105 cxSetAdvancedDestructor(c, destr, data) 105 cxSetAdvancedDestructor(c, destr, data)
106 106
107 // use in your collection's implementation 107 // use in your collection's implementation
108 cx_invoke_destructor(c, elem) 108 cx_invoke_destructor(c, elem)
109 cx_invoke_destructor_raw(c, elem)
109 110
110 // the following two can be used to optimize loops 111 // the following two can be used to optimize loops
111 cx_invoke_simple_destructor(c, elem) 112 cx_invoke_simple_destructor(c, elem)
112 cx_invoke_advanced_destructor(c, elem) 113 cx_invoke_advanced_destructor(c, elem)
113 ``` 114 ```
118 119
119 Your collection _should_ be supporting destructors by invoking `cx_invoke_destructor()` whenever an element 120 Your collection _should_ be supporting destructors by invoking `cx_invoke_destructor()` whenever an element
120 is removed from your collection _without_ being returned to the caller. 121 is removed from your collection _without_ being returned to the caller.
121 This macro will invoke a simple destructor, if one is assigned, first, and then the advanced destructor (again, if assigned). 122 This macro will invoke a simple destructor, if one is assigned, first, and then the advanced destructor (again, if assigned).
122 123
123 > Destructor functions are always invoked with a pointer to the element in your collection. 124 > Destructor functions are invoked with a pointer to the element in your collection, unless you use `cx_invoke_destructor_raw()`.
124 > If your collection is storing pointers (i.e. `cxCollectionStoresPointers()` returns `true`) 125 > If your collection is storing pointers (i.e. `cxCollectionStoresPointers()` returns `true`)
125 > the `cx_invoke_destructor()` will make sure that the pointer to the element is dereferenced first, 126 > the `cx_invoke_destructor()` will make sure that the pointer to the element is dereferenced first,
126 > so that the destructor functions are _always_ invoked with a pointer to the actual element. 127 > so that the destructor functions are _always_ invoked with a pointer to the actual element.
127 > 128 >
128 > This is different to how [comparator functions](#comparator-functions) work. 129 > This is different to how [comparator functions](#comparator-functions) work.
130 > If you want the same behavior as for comparators, use `cx_invoke_destructor_raw()`.
129 {style="note"} 131 {style="note"}
130 132
131 <seealso> 133 <seealso>
132 <category ref="apidoc"> 134 <category ref="apidoc">
133 <a href="https://ucx.sourceforge.io/api/collection_8h.html">collection.h</a> 135 <a href="https://ucx.sourceforge.io/api/collection_8h.html">collection.h</a>

mercurial