src/cx/iterator.h

changeset 851
adb4e0737c33
parent 850
b2bc48c2b251
child 852
16e2a3391e88
equal deleted inserted replaced
850:b2bc48c2b251 851:adb4e0737c33
272 #define cx_foreach(type, elem, iter) \ 272 #define cx_foreach(type, elem, iter) \
273 for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter)) != NULL ; cxIteratorNext(iter)) 273 for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter)) != NULL ; cxIteratorNext(iter))
274 274
275 275
276 /** 276 /**
277 * Creates a mutating iterator for the specified plain array.
278 *
279 * The \p array can be \c NULL in which case the iterator will be immediately
280 * initialized such that #cxIteratorValid() returns \c false.
281 *
282 *
283 * @param array a pointer to the array (can be \c NULL)
284 * @param elem_size the size of one array element
285 * @param elem_count the number of elements in the array
286 * @return an iterator for the specified array
287 */
288 __attribute__((__warn_unused_result__))
289 CxIterator cxIterator(
290 void const *array,
291 size_t elem_size,
292 size_t elem_count
293 );
294
295 /**
277 * Creates an iterator for the specified plain array. 296 * Creates an iterator for the specified plain array.
278 * 297 *
279 * While the iterator is in use, the array may only be altered by removing 298 * While the iterator is in use, the array may only be altered by removing
280 * elements through #cxIteratorFlagRemoval(). Every other change to the array 299 * elements through #cxIteratorFlagRemoval(). Every other change to the array
281 * will bring this iterator to an undefined state. 300 * will bring this iterator to an undefined state.
295 * @param remove_keeps_order \c true if the order of elements must be preserved 314 * @param remove_keeps_order \c true if the order of elements must be preserved
296 * when removing an element 315 * when removing an element
297 * @return an iterator for the specified array 316 * @return an iterator for the specified array
298 */ 317 */
299 __attribute__((__warn_unused_result__)) 318 __attribute__((__warn_unused_result__))
300 CxMutIterator cxIterator( // TODO: unify the iterator types 319 CxMutIterator cxMutIterator(
301 void *array, 320 void *array,
302 size_t elem_size, 321 size_t elem_size,
303 size_t elem_count, 322 size_t elem_count,
304 bool remove_keeps_order 323 bool remove_keeps_order
305 ); 324 );

mercurial