Add method _count_if

This commit is contained in:
Patrick Pelissier committed 2018-07-15 11:05:58 +02:00
1 parent b2f005239b
commit fcdfd836ec
2 files changed
+17

No files matched your search

+14
View File
@@ -167,6 +167,20 @@
return count; \
} \
\
static inline size_t \
M_C(name, _count_if) (container_t l, bool (*func)(type_t const data)) \
{ \
it_t it; \
size_t count = 0; \
for (M_GET_IT_FIRST cont_oplist (it, l); \
!M_GET_IT_END_P cont_oplist (it) ; \
M_GET_IT_NEXT cont_oplist (it)) { \
if (func (*M_GET_IT_CREF cont_oplist (it))) \
count++ ; \
} \
return count; \
} \
\
static inline void \
M_C(name, _map) (container_t l, void (*f)(type_t const) ) \
{ \
+3
View File
@@ -168,6 +168,9 @@ static void test_array(void)
assert( algo_array_count(l, -1) == 0);
assert( algo_array_sort_p(l) == false);
assert( algo_array_count_if(l, func_test_42) == 1);
assert( algo_array_count_if(l, func_test_101) == 0);
array_int_it_t it;
algo_array_find_last(it, l, 17);
assert (!array_int_end_p (it));