cvector · Section 3
cvec_append_cvec
NAME
cvec_append_cvec - append one vector onto another (type-inferred, fatal on failure)
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cvector.h> cvec_append_cvec(v_to, v_from);
DESCRIPTION
A wrapper for cvector_append_cvector() that calls ccol__fatal_err() when the append fails, so a caller that has no useful way to recover from an allocation failure doesn't need to test a return value. Every element of v_from is copied onto the end of v_to in one bulk copy and v_from is left unchanged, so afterwards the two vectors hold independent copies of the appended elements. The append is all or nothing: either every element lands in v_to or v_to stays exactly as it was.
PARAMETERS
v_to Destination vector. The macro appends to it. v_from Source vector. The macro reads it and leaves it unchanged.
NOTES
The macro stops the program with ccol__fatal_err() when the append fails, which happens when the allocation fails or when the new element count would be more than ccol_max_elem_count. Both vectors must have the same element size; different sizes make the macro assert rather than report a failure. It also asserts when either vector is NULL. An empty v_from succeeds and leaves v_to unchanged. Appending a vector to itself is supported and doubles its content. The elements are copied, not moved, so destroying v_from later doesn't disturb v_to. For a vector of pointers both vectors end up with the same pointer values, and only one of them can own the buffers behind those pointers. To handle a failed append yourself, call cvector_append_cvector(3) directly; that function doesn't stop the program.
EXAMPLES
cvec_construct(a, int); cvec_construct(b, int); cvec_push(a, 1); cvec_push(b, 2); cvec_push(b, 3); cvec_append_cvec(a, b); // cvec_size(a) == 3, cvec_size(b) == 2 cvec_destroy(a); cvec_destroy(b);
SEE ALSO
cvector_append_cvector(3), cvec_append_array(3), cvec_reserve(3)