diff -r d4baf4dd55c3 -r fe0d69d72bcd src/cx/iterator.h --- a/src/cx/iterator.h Thu May 23 19:29:14 2024 +0200 +++ b/src/cx/iterator.h Thu May 23 20:29:28 2024 +0200 @@ -38,45 +38,54 @@ #include "common.h" -#define CX_ITERATOR_BASE \ - /** \ - * True iff the iterator points to valid data. \ - */ \ - __attribute__ ((__nonnull__)) \ - bool (*valid)(void const *); \ - /** \ - * Returns a pointer to the current element. \ - * \ - * When valid returns false, the behavior of this function is undefined. \ - */ \ - __attribute__ ((__nonnull__)) \ - void *(*current)(void const *); \ - /** \ - * Original implementation in case the function needs to be wrapped. \ - */ \ - __attribute__ ((__nonnull__)) \ - void *(*current_impl)(void const *); \ - /** \ - * Advances the iterator. \ - * \ - * When valid returns false, the behavior of this function is undefined. \ - */ \ - __attribute__ ((__nonnull__)) \ - void (*next)(void *); \ - /** \ - * Indicates whether this iterator may remove elements. \ - */ \ - bool mutating; \ - /** \ - * Internal flag for removing the current element when advancing. \ - */ \ +struct cx_iterator_base_s { + /** + * True iff the iterator points to valid data. + */ + __attribute__ ((__nonnull__)) + bool (*valid)(void const *); + + /** + * Returns a pointer to the current element. + * + * When valid returns false, the behavior of this function is undefined. + */ + __attribute__ ((__nonnull__)) + void *(*current)(void const *); + + /** + * Original implementation in case the function needs to be wrapped. + */ + __attribute__ ((__nonnull__)) + void *(*current_impl)(void const *); + + /** + * Advances the iterator. + * + * When valid returns false, the behavior of this function is undefined. + */ + __attribute__ ((__nonnull__)) + void (*next)(void *); + /** + * Indicates whether this iterator may remove elements. + */ + bool mutating; + /** + * Internal flag for removing the current element when advancing. + */ bool remove; +}; + +/** + * Declares base attributes for an iterator. + */ +#define CX_ITERATOR_BASE struct cx_iterator_base_s base /** * Internal iterator struct - use CxIterator. */ struct cx_iterator_s { - CX_ITERATOR_BASE + CX_ITERATOR_BASE; /** * Handle for the current element. @@ -157,7 +166,7 @@ * @param iter the iterator * @return true iff the iterator points to valid data */ -#define cxIteratorValid(iter) (iter).valid(&(iter)) +#define cxIteratorValid(iter) (iter).base.valid(&(iter)) /** * Returns a pointer to the current element. @@ -167,21 +176,21 @@ * @param iter the iterator * @return a pointer to the current element */ -#define cxIteratorCurrent(iter) (iter).current(&iter) +#define cxIteratorCurrent(iter) (iter).base.current(&iter) /** * Advances the iterator to the next element. * * @param iter the iterator */ -#define cxIteratorNext(iter) (iter).next(&iter) +#define cxIteratorNext(iter) (iter).base.next(&iter) /** * Flags the current element for removal, if this iterator is mutating. * * @param iter the iterator */ -#define cxIteratorFlagRemoval(iter) (iter).remove |= (iter).mutating +#define cxIteratorFlagRemoval(iter) (iter).base.remove |= (iter).base.mutating /** * Loops over an iterator.