Add method _push_move & _pop_move.
Add assertion on _pop_back to check that the container is not empty.
This commit is contained in:
1 parent
86083e3a92
commit
d0fe7f3e25
2 files changed
+36
-2
No files matched your search
@@ -72,6 +72,8 @@
|
|||||||
,CLEAN(M_C(name,_clean)) \
|
,CLEAN(M_C(name,_clean)) \
|
||||||
,PUSH(M_C(name,_push_back)) \
|
,PUSH(M_C(name,_push_back)) \
|
||||||
,POP(M_C(name,_pop_back)) \
|
,POP(M_C(name,_pop_back)) \
|
||||||
|
,PUSH_MOVE(M_C(name,_push_move)) \
|
||||||
|
,POP_MOVE(M_C(name,_pop_move)) \
|
||||||
,OPLIST(oplist) \
|
,OPLIST(oplist) \
|
||||||
,M_IF_METHOD(CMP, oplist)(SORT(M_C(name, _special_sort)),) \
|
,M_IF_METHOD(CMP, oplist)(SORT(M_C(name, _special_sort)),) \
|
||||||
,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \
|
,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \
|
||||||
@@ -254,6 +256,16 @@
|
|||||||
return NULL; \
|
return NULL; \
|
||||||
M_GET_INIT oplist(*data); \
|
M_GET_INIT oplist(*data); \
|
||||||
return data; \
|
return data; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
static inline void \
|
||||||
|
M_C(name, _push_move)(array_t v, type *x) \
|
||||||
|
{ \
|
||||||
|
assert (x != NULL); \
|
||||||
|
type *data = M_C(name, _push_raw)(v); \
|
||||||
|
if (M_UNLIKELY (data == NULL) ) \
|
||||||
|
return; \
|
||||||
|
M_DO_INIT_MOVE (oplist, *data, *x); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
@@ -371,11 +383,24 @@
|
|||||||
M_C(name, _pop_back)(type *dest, array_t v) \
|
M_C(name, _pop_back)(type *dest, array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
|
assert (v->size > 0); \
|
||||||
v->size--; \
|
v->size--; \
|
||||||
if (dest) \
|
if (dest) { \
|
||||||
M_DO_MOVE (oplist, *dest, v->ptr[v->size]); \
|
M_DO_MOVE (oplist, *dest, v->ptr[v->size]); \
|
||||||
else \
|
} else { \
|
||||||
M_GET_CLEAR oplist (v->ptr[v->size]); \
|
M_GET_CLEAR oplist (v->ptr[v->size]); \
|
||||||
|
} \
|
||||||
|
ARRAYI_CONTRACT(v); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
static inline void \
|
||||||
|
M_C(name, _pop_move)(type *dest, array_t v) \
|
||||||
|
{ \
|
||||||
|
ARRAYI_CONTRACT(v); \
|
||||||
|
assert (v->size > 0); \
|
||||||
|
assert (dest != NULL); \
|
||||||
|
v->size--; \
|
||||||
|
M_DO_INIT_MOVE (oplist, *dest, v->ptr[v->size]); \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
|||||||
@@ -163,6 +163,15 @@ static void test_uint(void)
|
|||||||
assert (i == *array_uint_get(v, i));
|
assert (i == *array_uint_get(v, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
x = 1478963;
|
||||||
|
s = *array_uint_back(v);
|
||||||
|
array_uint_push_move(v, &x);
|
||||||
|
assert (*array_uint_back(v) == 1478963);
|
||||||
|
x = 0;
|
||||||
|
array_uint_pop_move(&x, v);
|
||||||
|
assert (x == 1478963);
|
||||||
|
assert (s == *array_uint_back(v));
|
||||||
|
|
||||||
array_uint_clear(v);
|
array_uint_clear(v);
|
||||||
array_uint_clear(v2);
|
array_uint_clear(v2);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user