From c7c9378b465c8553f58511c49ffd743f7330d3a2 Mon Sep 17 00:00:00 2001 From: Bredor <40574176+freedan42x@users.noreply.github.com> Date: Wed, 27 Dec 2023 22:10:12 +0200 Subject: [PATCH] Create Beta - Print Vector to Stream without using for-loops (simple version).cpp --- ...eam without using for-loops (simple version).cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 cpp/Beta - Print Vector to Stream without using for-loops (simple version).cpp 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()); +}