diff --git a/m-algo.h b/m-algo.h index cd34648d..83e60cea 100644 --- a/m-algo.h +++ b/m-algo.h @@ -218,6 +218,25 @@ *max_p = max; \ } \ \ + static inline bool M_C(name, _sort_p)(container_t l) \ + { \ + it_t it1; \ + it_t it2; \ + M_GET_IT_FIRST cont_oplist (it1, l); \ + M_GET_IT_SET cont_oplist (it2, it1); \ + M_GET_IT_NEXT cont_oplist (it2); \ + while (!M_GET_IT_END_P cont_oplist (it2)) { \ + const type_t *ref1 = M_GET_IT_CREF cont_oplist (it1); \ + const type_t *ref2 = M_GET_IT_CREF cont_oplist (it2); \ + if (M_GET_CMP type_oplist (*ref1, *ref2) > 0) { \ + return false; \ + } \ + M_GET_IT_SET cont_oplist (it1, it2); \ + M_GET_IT_NEXT cont_oplist (it2); \ + } \ + return true; \ + } \ + \ /* Sort can be generated from 3 algorithms: */ \ /* - a specialized version defined by the container */ \ /* - an insertion sort (need 'previous' method) */ \ diff --git a/tests/test-malgo.c b/tests/test-malgo.c index f51dc518..1c03e50e 100644 --- a/tests/test-malgo.c +++ b/tests/test-malgo.c @@ -54,8 +54,9 @@ static void test_list(void) for(int i = -100; i < 100; i+=2) list_int_push_back (l, i); + assert (!algo_list_sort_p(l)); algo_list_sort(l); - // TODO: assert (algo_list_sort_p(l)); + assert (algo_list_sort_p(l)); list_int_clear(l);