1.1 --- a/src/cx/list.h Mon Dec 18 16:14:07 2023 +0100 1.2 +++ b/src/cx/list.h Mon Dec 18 18:22:53 2023 +0100 1.3 @@ -136,11 +136,12 @@ 1.4 ); 1.5 1.6 /** 1.7 - * Member function for finding an element. 1.8 + * Member function for finding and optionally removing an element. 1.9 */ 1.10 - ssize_t (*find)( 1.11 - struct cx_list_s const *list, 1.12 - void const *elem 1.13 + ssize_t (*find_remove)( 1.14 + struct cx_list_s *list, 1.15 + void const *elem, 1.16 + bool remove 1.17 ); 1.18 1.19 /** 1.20 @@ -579,7 +580,25 @@ 1.21 CxList const *list, 1.22 void const *elem 1.23 ) { 1.24 - return list->cl->find(list, elem); 1.25 + return list->cl->find_remove((CxList*)list, elem, false); 1.26 +} 1.27 + 1.28 +/** 1.29 + * Removes and returns the index of the first element that equals \p elem. 1.30 + * 1.31 + * Determining equality is performed by the list's comparator function. 1.32 + * 1.33 + * @param list the list 1.34 + * @param elem the element to find and remove 1.35 + * @return the index of the now removed element or a negative 1.36 + * value when the element is not found or could not be removed 1.37 + */ 1.38 +__attribute__((__nonnull__)) 1.39 +static inline ssize_t cxListFindRemove( 1.40 + CxList *list, 1.41 + void const *elem 1.42 +) { 1.43 + return list->cl->find_remove(list, elem, true); 1.44 } 1.45 1.46 /**