src/cx/iterator.h

changeset 496
1a07e24801a9
parent 495
2856c74e18ba
child 497
b182a8b8a1af
     1.1 --- a/src/cx/iterator.h	Sat Jan 22 18:49:06 2022 +0100
     1.2 +++ b/src/cx/iterator.h	Sat Jan 22 19:04:32 2022 +0100
     1.3 @@ -100,7 +100,7 @@
     1.4   *
     1.5   * This is especially false for past-the-end iterators.
     1.6   *
     1.7 - * @param iter the iterator
     1.8 + * @param iter a pointer to the iterator
     1.9   * @return true iff the iterator points to valid data
    1.10   */
    1.11  __attribute__ ((__nonnull__))
    1.12 @@ -113,7 +113,7 @@
    1.13   *
    1.14   * The behavior is undefined if this iterator is invalid.
    1.15   *
    1.16 - * @param iter the iterator
    1.17 + * @param iter a pointer to the iterator
    1.18   * @return a pointer to the current element
    1.19   */
    1.20  __attribute__ ((__nonnull__))
    1.21 @@ -124,11 +124,20 @@
    1.22  /**
    1.23   * Advances the iterator to the next element.
    1.24   *
    1.25 - * @param iter the iterator
    1.26 + * @param iter a pointer to the iterator
    1.27   */
    1.28  __attribute__ ((__nonnull__))
    1.29  static inline void cxIteratorNext(CxIterator *iter) {
    1.30      iter->next(iter);
    1.31  }
    1.32  
    1.33 +/**
    1.34 + * Loops over an iterator.
    1.35 + * @param type the type of the elements
    1.36 + * @param elem the name of the iteration variable
    1.37 + * @param iter the iterator
    1.38 + */
    1.39 +#define cx_foreach(type, elem, iter) \
    1.40 +for (type *elem; cxIteratorValid(&iter) && (elem = cxIteratorCurrent(&iter)) != NULL ; cxIteratorNext(&iter)) // NOLINT(bugprone-macro-parentheses)
    1.41 +
    1.42  #endif /* UCX_ITERATOR_H */

mercurial