diff --git a/cvector.h b/cvector.h index 8adfa77..c6f1801 100644 --- a/cvector.h +++ b/cvector.h @@ -108,6 +108,21 @@ typedef struct cvector_metadata_t { } \ } while (0) +/* + * @brief cvector_init - Initialize a vector. The vector must be NULL for this to do anything. + * @param vec - the vector + * @param capacity - vector capacity to reserve + * @param elem_destructor_fn - element destructor function + * @return void + */ +#define cvector_init(vec, capacity, elem_destructor_fn) \ + do { \ + if (!(vec)) { \ + cvector_reserve((vec), capacity); \ + cvector_set_elem_destructor((vec), (elem_destructor_fn)); \ + } \ + } while (0) + /** * @brief cvector_erase - removes the element at index i from the vector * @param vec - the vector