Skip to content

Commit

Permalink
Add cvector() syntactic sugar alias macro for cvector_vector_type() (#59
Browse files Browse the repository at this point in the history
)

Co-authored-by: Evan Teran <[email protected]>
  • Loading branch information
RobLoach and eteran authored Oct 31, 2023
1 parent d6cb7c2 commit 6ab31d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ typedef struct cvector_metadata_t {
#define cvector_vector_type(type) type *

/**
* @brief cvector - Syntactic sugar to retrieve a vector type
*
* @param type The type of vector to act on.
*/
#define cvector(type) cvector_vector_type(type)

/*
* @brief cvector_iterator - The iterator type used for cvector
*/
#define cvector_iterator(type) cvector_vector_type(type)
Expand Down
6 changes: 3 additions & 3 deletions example.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ int main(int argc, char *argv[]) {
* and you'd have a vector of floats :-). NULL will have a size
* and capacity of 0. Additionally, vector_begin and vector_end will
* return NULL on a NULL vector. Alternatively, for clarity of writing
* you can use the cvector_vector_type macro to define a vector of a
* given type.
* you can use the cvector or cvector_vector_type macros to define a
* vector of a given type.
*/
cvector_vector_type(int) v = NULL;
cvector(int) v = NULL;

(void)argc;
(void)argv;
Expand Down
2 changes: 1 addition & 1 deletion unit-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ UTEST(test, vector_index) {
}

UTEST(test, vector_insert_delete) {
cvector_vector_type(int) a = NULL;
cvector(int) a = NULL;

cvector_push_back(a, 1);
cvector_push_back(a, 5);
Expand Down

0 comments on commit 6ab31d9

Please sign in to comment.