VecMergeL
Description
Append all elements of v2 to the end of v. L-value form: when the destination has no copy_init handler, ownership of v2’s storage transfers and v2 is left empty on success. With a deep-copy handler, v2 is unchanged.
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in,out | Destination vector. |
v2 |
in,out | Source vector. May be emptied on success. |
Success
Returns true. v->length grows by the previous v2->length; the appended elements occupy the new tail of v. When v has no copy_init handler, v2->data ownership has transferred into v and v2 is left empty (length 0, capacity 0, data freed and pointer reset). With a deep-copy handler, v2 is unchanged.
Failure
Returns false on allocation failure. Both v and v2 are unchanged.
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 && (VecLen(&vec3) == 2);
result = result && (VecLen(&vec4) == 0); // VecMergeL resets source vector
result = result && (VecBegin(&vec4) == NULL); // Test VecMergeL zero-on-take behavior with complex structures
bool test_lvalue_zero_on_take_merge(void) {
WriteFmt("Testing VecMergeL zero-on-take 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)
- In
Vec.Insert.c:501:
// Merge with L-value semantics
VecMergeL(&vec, &vec2);
// Check that the source vector is cleared
- In
Insert.h:429:
/// TAGS: Vec, Merge, Insert
///
#define VecMerge(v, v2) VecMergeL((v), (v2))
///
- In
Insert.h:917:
#define VecMustMergeL(v, v2) \
do { \
if (!VecMergeL((v), (v2))) { \
LOG_FATAL("VecMustMergeL failed"); \
} \- In
Insert.h:351:
/// TAGS: Str, Merge, LValue, Ownership
///
#define StrMergeL(str, str2) VecMergeL((str), (str2))
///
Last updated on