Skip to content

Commit

Permalink
add cvector_init (#51)
Browse files Browse the repository at this point in the history
* add cvector_init

* formatting
  • Loading branch information
DDexxeDD authored Feb 28, 2023
1 parent 793dfbb commit 532391e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 532391e

Please sign in to comment.