aboutsummaryrefslogtreecommitdiff
path: root/collections/vector/vector.adoc
diff options
context:
space:
mode:
Diffstat (limited to 'collections/vector/vector.adoc')
-rw-r--r--collections/vector/vector.adoc45
1 files changed, 44 insertions, 1 deletions
diff --git a/collections/vector/vector.adoc b/collections/vector/vector.adoc
index 3ffd10c..fbb0b32 100644
--- a/collections/vector/vector.adoc
+++ b/collections/vector/vector.adoc
@@ -1,7 +1,7 @@
Vector
======
Tucker Evans
-v0.5, 2020-07-02
+v0.6, 2020-07-02
A basic vector, that hold pointers to your data structures.
@@ -169,3 +169,46 @@ vec_clear(vector);
assert(vec_size(vector) == 0);
vec_free(vector);
----
+
+[[vec_print]]
++void vec_print(vec *self, (char* to_string(void*)))+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Prints out the contents of the vector +self+ to +stdout+ (surounded by square
+brackets and separated by commas ','). +to_string+ is a function that takes a
+pointer to the type of elements stored in +self+ and returns a string
+representation.
+
+Examples
+^^^^^^^^
+[source,c]
+----
+#include "vector.h"
+#include <string.h>
+
+char* to_string(str)
+void *str;
+{
+ return str;
+}
+
+int main()
+{
+char *str1 = "ONE";
+char *str2 = "TWO";
+char *str3 = "THREE";
+
+vec *vector = vec_new();
+vec_push(vector, str_dup(str1));
+vec_push(vector, str_dup(str2));
+vec_push(vector, str_dup(str3));
+
+printf("VEC CONTENTS:\n\t")
+vec_print(vector, to_string)
+}
+----
+
+Output:
+----
+VEC_CONTENTS:
+ [ONE,TWO,THREE]
+----