Sun, 16 Feb 2025 12:59:14 +0100
add missing documentation about creating iterators
relates to #451
docs/Writerside/topics/iterator.h.md | file | annotate | diff | comparison | revisions |
--- a/docs/Writerside/topics/iterator.h.md Sun Feb 16 12:40:51 2025 +0100 +++ b/docs/Writerside/topics/iterator.h.md Sun Feb 16 12:59:14 2025 +0100 @@ -19,9 +19,34 @@ }; ``` -## Overview +## Creating an Iterator + +The following functions create iterators over plain C arrays: + +```C +#include <cx/iterator.h> +CxIterator cxIterator(const void *array, + size_t elem_size, size_t elem_count); + +CxIterator cxMutIterator(void *array, + size_t elem_size, size_t elem_count, bool remove_keeps_order); + +CxIterator cxIteratorPtr(const void *array, size_t elem_count); + +CxIterator cxMutIteratorPtr(void *array, size_t elem_count, + bool remove_keeps_order); +``` +The `cxIterator()` function creates an iterator over the elements of `array` where +each element is `elem_size` bytes large and the array contains a total of `elem_count` elements. +The `cxMutIterator()` function creates an equivalent [mutating iterator](#mutating-iterators). + +The `cxIteratorPtr()` and `cxMutIteratorPtr()` functions are equivalent to +the `cxIteratorPtr()` and `cxMutIteratorPtr()`, except they assume `sizeof(void*)` as the `elem_size`. + +The UCX collections also define functions for creating iterators over their items. +You can read more about them in the respective Sections of the documentation. ## Using an Iterator