184 |
184 |
185 You do not always need all fields in the iterator structure, depending on your use case. |
185 You do not always need all fields in the iterator structure, depending on your use case. |
186 Sometimes you only need the `index` (for example when iterating over simple lists), and other times you will need the |
186 Sometimes you only need the `index` (for example when iterating over simple lists), and other times you will need the |
187 `slot` and `kv_data` fields (for example when iterating over maps). |
187 `slot` and `kv_data` fields (for example when iterating over maps). |
188 |
188 |
|
189 If the predefined fields are insufficient for your use case, you can alternatively create your own iterator structure |
|
190 and place the `CX_ITERATOR_BASE` macro inside. |
|
191 |
189 Usually an iterator is not mutating the collection it is iterating over. |
192 Usually an iterator is not mutating the collection it is iterating over. |
190 In some programming languages it is even disallowed to change the collection while iterating with foreach. |
193 In some programming languages it is even disallowed to change the collection while iterating with foreach. |
191 But sometimes it is desirable to remove an element from the collection while iterating over it. |
194 But sometimes it is desirable to remove an element from the collection while iterating over it. |
192 This is, what the `CxMutIterator` is for. |
195 For this purpose, most collections allow the creation of a _mutating_ iterator. |
193 The only differences are, that the `mutating` flag is `true` and the `src_handle` is not const. |
196 The only differences are, that the `mutating` flag is `true` and the `src_handle` is not const. |
194 On mutating iterators it is allowed to call the `cxFlagForRemoval()` function, which instructs the iterator to remove |
197 On mutating iterators it is allowed to call the `cxFlagForRemoval()` function, which instructs the iterator to remove |
195 the current element from the collection on the next call to `cxIteratorNext()` and clear the flag afterward. |
198 the current element from the collection on the next call to `cxIteratorNext()` and clear the flag afterward. |
196 If you are implementing your own iterator, it is up to you to implement this behavior in your `next` method, or |
199 If you are implementing your own iterator, it is up to you to implement this behavior. |
197 make the implementation of the `flag_removal` method always return `false`. |
|
198 |
200 |
199 ## Collection |
201 ## Collection |
200 |
202 |
201 *Header file:* [collection.h](api/collection_8h.html) |
203 *Header file:* [collection.h](api/collection_8h.html) |
202 |
204 |