Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cvector() syntactic sugar alias macro for cvector_vector_type() #59

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading