Skip to content

Commit

Permalink
Add cvector_iterator (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach authored Oct 31, 2023
1 parent 61ccddf commit fa19a27
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ typedef struct cvector_metadata_t {
*/
#define cvector_vector_type(type) type *

/**
* @brief cvector_iterator - The iterator type used for cvector
*/
#define cvector_iterator(type) cvector_vector_type(type)

/**
* @brief cvector_vec_to_base - For internal use, converts a vector pointer to a metadata pointer
* @param vec - the vector
Expand Down
2 changes: 1 addition & 1 deletion example.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) {

/* iterator over the vector using "iterator" style */
if (v) {
int *it;
cvector_iterator(int) it;
int i = 0;
for (it = cvector_begin(v); it != cvector_end(v); ++it) {
printf("v[%d] = %d\n", i, *it);
Expand Down
2 changes: 1 addition & 1 deletion test.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {

/* iterator over the vector using "iterator" style */
if (v) {
int *it;
cvector_iterator(int) it;
int i = 0;
for (it = cvector_begin(v); it != cvector_end(v); ++it) {
printf("v[%d] = %d\n", i, *it);
Expand Down
4 changes: 2 additions & 2 deletions unit-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ UTEST(test, vector_iterator) {

/* iterator over the vector using "iterator" style */
if (v) {
int *it;
cvector_iterator(int) it;
int i = 0;
for (it = cvector_begin(v); it != cvector_end(v); ++it) {
switch (i) {
Expand Down Expand Up @@ -182,7 +182,7 @@ UTEST(test, vector_free_all) {
}

UTEST(test, vector_for_each_int) {
char **it;
cvector_iterator(char *) it;
int i;
cvector_vector_type(char *) v = NULL;
for (i = 0; i < 10; ++i) {
Expand Down

0 comments on commit fa19a27

Please sign in to comment.