src/cx/iterator.h

changeset 829
7d4e31d295af
parent 759
475335643af4
equal deleted inserted replaced
828:88fa3381206d 829:7d4e31d295af
69 */ 69 */
70 __attribute__ ((__nonnull__)) 70 __attribute__ ((__nonnull__))
71 void (*next)(void *); 71 void (*next)(void *);
72 72
73 /** 73 /**
74 * Flag current element for removal, if possible.
75 *
76 * When valid returns false, the behavior of this function is undefined.
77 */
78 __attribute__ ((__nonnull__))
79 bool (*flag_removal)(void *);
80
81 /**
82 * Indicates whether this iterator may remove elements. 74 * Indicates whether this iterator may remove elements.
83 */ 75 */
84 bool mutating; 76 bool mutating;
85 77
86 /** 78 /**
241 * @param iter the iterator 233 * @param iter the iterator
242 */ 234 */
243 #define cxIteratorNext(iter) (iter).base.next(&iter) 235 #define cxIteratorNext(iter) (iter).base.next(&iter)
244 236
245 /** 237 /**
246 * Flags the current element for removal. 238 * Flags the current element for removal, if this iterator is mutating.
247 * 239 *
248 * @param iter the iterator 240 * @param iter the iterator
249 * @return false if this iterator cannot remove the element 241 */
250 */ 242 #define cxIteratorFlagRemoval(iter) (iter).base.remove |= (iter).base.mutating
251 #define cxIteratorFlagRemoval(iter) (iter).base.flag_removal(&iter)
252 243
253 /** 244 /**
254 * Loops over an iterator. 245 * Loops over an iterator.
255 * @param type the type of the elements 246 * @param type the type of the elements
256 * @param elem the name of the iteration variable 247 * @param elem the name of the iteration variable

mercurial