also support NULL in index-based iterator generating functions

Mon, 18 Aug 2025 23:00:55 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 18 Aug 2025 23:00:55 +0200
changeset 1343
b2ba79f4cb62
parent 1342
fe3ac6b1cf57
child 1344
8afaeb395b3c

also support NULL in index-based iterator generating functions

docs/Writerside/topics/list.h.md file | annotate | diff | comparison | revisions
src/cx/list.h file | annotate | diff | comparison | revisions
--- a/docs/Writerside/topics/list.h.md	Sun Aug 17 23:10:25 2025 +0200
+++ b/docs/Writerside/topics/list.h.md	Mon Aug 18 23:00:55 2025 +0200
@@ -290,7 +290,7 @@
 The functions with `Mut` in are equivalently, except that they create a [mutating iterator](iterator.h.md#mutating-iterators).
 Removing elements via a mutating iterator will cause an invocation of the [destructor functions](collection.h.md#destructor-functions) for the removed element. 
 
-If is safe to specify an out-of-bounds index in which case an iterator is returned for which `cxIteratorValid()` returns `false`, immediately.
+If is safe to specify an out-of-bounds index, or a `NULL` pointer, in which cases an iterator is returned for which `cxIteratorValid()` returns `false`, immediately.
 
 ## Reorder
 
--- a/src/cx/list.h	Sun Aug 17 23:10:25 2025 +0200
+++ b/src/cx/list.h	Mon Aug 18 23:00:55 2025 +0200
@@ -872,18 +872,18 @@
  *
  * The returned iterator is position-aware.
  *
- * If the index is out of range, a past-the-end iterator will be returned.
+ * If the index is out of range or @p list is @c NULL, a past-the-end iterator will be returned.
  *
  * @param list the list
  * @param index the index where the iterator shall point at
  * @return a new iterator
  */
-cx_attr_nonnull
 cx_attr_nodiscard
 static inline CxIterator cxListIteratorAt(
         const CxList *list,
         size_t index
 ) {
+    if (list == NULL) list = cxEmptyList;
     return list->cl->iterator(list, index, false);
 }
 
@@ -892,18 +892,18 @@
  *
  * The returned iterator is position-aware.
  *
- * If the index is out of range, a past-the-end iterator will be returned.
+ * If the index is out of range or @p list is @c NULL, a past-the-end iterator will be returned.
  *
  * @param list the list
  * @param index the index where the iterator shall point at
  * @return a new iterator
  */
-cx_attr_nonnull
 cx_attr_nodiscard
 static inline CxIterator cxListBackwardsIteratorAt(
         const CxList *list,
         size_t index
 ) {
+    if (list == NULL) list = cxEmptyList;
     return list->cl->iterator(list, index, true);
 }
 

mercurial