vt_copy 3 2016-03-05 genvector manual

NAME

vt_copy - return a pointer to an element

SYNPOSIS

int vt_copy(vt_t *dst_vect, vt_size_t dst_idx, vt_t *src_vect, vt_size_t src_idx, vt_size_t num_elems);

DESCRIPTION

vt_copy copies num_elems elements from src_vect, starting from index src_idx to dst_vect starting from dst_idx. dst_vect must be initialized before the call. dst_vect is enlarged as needed. src_idx must be in bounds, num_elems is autoamtically adjusted if points beyond the end of src_vect.

If dst_vect has a copy callback, it is used for copying elements. If dst_vect has a destructor, it is called on all elements overwritten prior to the copy call.

If dst_vect has element initialization, and there are new elements to be implicitly initialized (when dst_idx is larger than dst_vect's used), it is called for each such element. If dst_vect has a constructor, it is called for those elements.

If dst_vect has a copy callback, the order of copying is normally from low index to high index. However, when copying elements within a vector (src_vect == dst_vect), the order of copy may be swapped, copying elements with the higher indices first, to avoid overwriting source elements (the "memmove() problem").

Note: vt_t and the vt_ prefix are type-dependant, see vt_t(7).

Arguments:
dst_vect Copy destination vector, already initialized using vt_init.
dst_idx The index of the first element to be overwritten in dst_vect.
src_vect Copy source vector, already initialized using vt_init. May be the same as dst_vect.
dst_idx The index of the first element to be copied from src_vect.
num_elems Number of elements to copy.

RETURN VALUE

Returns 0 on success, -1 on error. Error conditions include: failed to allocate or construct elements in the destination vector, user specified copy function failed, source index is beyond the end of the source vector. On constructor or copy failure, the new state of the vector, especially regarding to the fields of any new element added before the failure, is unspecified.

SEE ALSO

vt_copy 3 2016-03-05 genvector manual