Skip to content

VecMergeL

VecMergeL

Description

Merge two vectors and store the result in the first vector, with L-value semantics. Call to this makes sure, either both vectors have their own ownerships, or only one owns the objects. Meaning none of the two lists share ownership.

Ownership transfer takes place only if (v) does not create it’s own copies of objects. Vectors create their own copy only if copy_init method is provided, otherwise simple memcpy is performed, which is the case where objects tend to share ownership, that this method automatically resolves for you.

Success

v

Failure

Does not return on failure

Usage example (Cross-references)

Usage examples (Cross-references)
    
        // Merge vec4 into vec3 with ownership transfer
        VecMergeL(&vec3, &vec4);
    
        // Check vector lengths
        // Check vector lengths
        result = result && (vec3.length == 2);
        result = result && (vec4.length == 0); // VecMergeL resets source vector
        result = result && (vec4.data == NULL);
    // Test VecMergeL memset behavior with complex structures
    bool test_lvalue_memset_merge(void) {
        WriteFmt("Testing VecMergeL memset with complex structures\n");
    
        // Create a vector with no copy_init but with copy_deinit for proper cleanup
    
        // Now merge vec2 into vec1 with L-value semantics
        VecMergeL(&vec1, &vec2);
    
        // Check that vec2 is now empty (data has been transferred)
    
        // Merge with L-value semantics
        VecMergeL(&vec, &vec2);
    
        // Check that the source vector is cleared
    /// FAILURE : Does not return on failure
    ///
    #define VecMerge(v, v2) VecMergeL((v), (v2))
    
    ///
    /// FAILURE : NULL
    ///
    #define StrMergeL(str, str2) VecMergeL((str), (str2))
    
    ///
Last updated on