Add move constructor to ql module

This commit is contained in:
Yinan Zhang 2020-04-02 13:14:24 -07:00
parent a62b7ed928
commit 4b66297ea0
2 changed files with 27 additions and 1 deletions

View File

@ -18,6 +18,11 @@ struct { \
(a_head)->qlh_first = NULL; \ (a_head)->qlh_first = NULL; \
} while (0) } while (0)
#define ql_move(a_head_dest, a_head_src) do { \
(a_head_dest)->qlh_first = (a_head_src)->qlh_first; \
(a_head_src)->qlh_first = NULL; \
} while (0)
#define ql_empty(a_head) ((a_head)->qlh_first == NULL) #define ql_empty(a_head) ((a_head)->qlh_first == NULL)
#define ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field) #define ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field)

View File

@ -282,6 +282,26 @@ TEST_BEGIN(test_ql_rotate) {
} }
TEST_END TEST_END
TEST_BEGIN(test_ql_move) {
list_head_t head_dest, head_src;
list_t entries[NENTRIES];
unsigned i;
ql_new(&head_src);
ql_move(&head_dest, &head_src);
test_empty_list(&head_src);
test_empty_list(&head_dest);
init_entries(entries, sizeof(entries)/sizeof(list_t));
for (i = 0; i < NENTRIES; i++) {
ql_tail_insert(&head_src, &entries[i], link);
}
ql_move(&head_dest, &head_src);
test_empty_list(&head_src);
test_entries_list(&head_dest, entries, NENTRIES);
}
TEST_END
int int
main(void) { main(void) {
return test( return test(
@ -292,5 +312,6 @@ main(void) {
test_ql_head_remove, test_ql_head_remove,
test_ql_insert, test_ql_insert,
test_ql_concat_split, test_ql_concat_split,
test_ql_rotate); test_ql_rotate,
test_ql_move);
} }