Skip to content

ListMerge

Description

Default merge aliases the L-form: append all nodes of l2 to the tail of l, transferring ownership of l2’s nodes when no deep-copy handler is configured (leaving l2 empty).

Parameters

Name Direction Description
l in,out Destination list.
l2 in,out Source list. May be emptied on success.

Success

Returns true; l->length grows by the previous l2->length.

Failure

Returns false on allocation failure; both l and l2 are unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
        ListPushBackR(&dest_a, 5);
        ListPushBackR(&src_a, 6);
        ListMerge(&dest_a, &src_a);
    
        bool result = list_matches(GENERIC_LIST(&dest_l), (const int[]) {1, 2, 3, 4}, 4);
    #define ListMustMerge(l, l2)                                                                                           \
        do {                                                                                                               \
            if (!ListMerge((l), (l2))) {                                                                                   \
                LOG_FATAL("ListMustMerge failed");                                                                         \
            }                                                                                                              \
Last updated on