Skip to content

Commit

Permalink
Create Beta - Print Vector to Stream without using for-loops (simple …
Browse files Browse the repository at this point in the history
…version).cpp
  • Loading branch information
freedan42x authored Dec 27, 2023
1 parent 5811063 commit c7c9378
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <ostream>
#include <vector>

template <typename T>
void print_vector(std::ostream& os, const std::vector<T>& vec) {
std::function<void(const T*, size_t)> helper = [&](auto rw, auto sz) {
if (sz == 0) return;
os << *rw;
helper(rw + 1, sz - 1);
};

helper(vec.data(), vec.size());
}

0 comments on commit c7c9378

Please sign in to comment.