Add _erase for array

This commit is contained in:
Patrick Pelissier committed 2018-10-27 23:30:21 +02:00
1 parent bd315c7e43
commit 6672becdd5
2 files changed
+17

No files matched your search

+9
View File
@@ -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)( \
+8
View File
@@ -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);
}