diff --git a/cpp/Beta - Print Vector to Stream without using for-loops (simple version).cpp b/cpp/Beta - Print Vector to Stream without using for-loops (simple version).cpp new file mode 100644 index 0000000..e69b172 --- /dev/null +++ b/cpp/Beta - Print Vector to Stream without using for-loops (simple version).cpp @@ -0,0 +1,13 @@ +#include +#include + +template +void print_vector(std::ostream& os, const std::vector& vec) { + std::function helper = [&](auto rw, auto sz) { + if (sz == 0) return; + os << *rw; + helper(rw + 1, sz - 1); + }; + + helper(vec.data(), vec.size()); +}