Skip to content

Instantly share code, notes, and snippets.

@hutorny
Created November 15, 2018 08:19
Show Gist options
  • Save hutorny/aa44d108ca65fb3fc91c400ce2791ec5 to your computer and use it in GitHub Desktop.
Save hutorny/aa44d108ca65fb3fc91c400ce2791ec5 to your computer and use it in GitHub Desktop.
A c++ template to print any iterable
#include <iterator>
#include <utility>
// see live example on http://coliru.stacked-crooked.com/a/591f4db5a008cb5a
template<class Stream, class Vector, class Begin = decltype(std::begin(std::declval<Vector>()))>
inline Stream& operator<<(Stream& stream, const Vector& vect) {
const char* dlm = "";
for(const auto& i : vect) { stream << dlm << i; dlm = ", "; }
return stream;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment