diff --git a/m-array.h b/m-array.h index 33232d3f..6c785e68 100644 --- a/m-array.h +++ b/m-array.h @@ -468,6 +468,15 @@ memmove(&v->ptr[i], &v->ptr[i+1], sizeof(type)*(v->size - i) ); \ v->size--; \ ARRAYI_CONTRACT(v); \ + } \ + \ + static inline bool \ + M_C(name, _erase)(array_t a, size_t i) \ + { \ + ARRAYI_CONTRACT(a); \ + if (i >= a->size) return false; \ + M_C(name, _pop_at)(NULL, a, i); \ + return true; \ } \ \ M_IF_METHOD(INIT, oplist)( \ diff --git a/tests/test-marray.c b/tests/test-marray.c index 4592cd5d..645766ce 100644 --- a/tests/test-marray.c +++ b/tests/test-marray.c @@ -175,6 +175,14 @@ static void test_uint(void) assert (x == 1478963); assert (s == *array_uint_back(v)); + s = array_uint_size (v); + bool b = array_uint_erase (v, 12459); + assert (b == false); + assert (s == array_uint_size (v)); + b = array_uint_erase (v, 0); + assert (b == true); + assert (s == array_uint_size (v)+1); + array_uint_clear(v); array_uint_clear(v2); }