From 80d98a39a6bc4b71c74f240df617495e816b98b9 Mon Sep 17 00:00:00 2001
From: Tucker Evans <tucker@tuckerevans.com>
Date: Thu, 2 Jul 2020 20:21:28 -0400
Subject: Add printing functions for vectors

---
 collections/vector/vector.adoc | 45 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

(limited to 'collections/vector/vector.adoc')

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]
+----
-- 
cgit v1.1

