From b1add835864a5907dc5a674f7eee2f3db038f704 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 3 Jan 2022 18:28:10 +0000 Subject: More complete and tested stream output support --- lib/stream_support.hpp | 52 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'lib/stream_support.hpp') diff --git a/lib/stream_support.hpp b/lib/stream_support.hpp index 449708c..932f7c4 100644 --- a/lib/stream_support.hpp +++ b/lib/stream_support.hpp @@ -3,30 +3,49 @@ #include #include #include +#include +#include namespace std { + template + std::ostream & + operator<<(std::ostream & s, const span v) + { + s << '('; + for (const auto & i : v) { + if (&i != &v.front()) + s << ", "; + s << i; + } + return s << ')'; + } + template std::ostream & operator<<(std::ostream & s, const glm::mat & m) { - for (int y = 0; y < m.length(); y++) { - const auto & col = m[y]; - for (int x = 0; x < col.length(); x++) { - s << col[x] << ", "; - } - s << "\n"; - } - return s; + return (s << std::span {&m[0], L}); } template std::ostream & operator<<(std::ostream & s, const glm::vec & v) { - for (int x = 0; x < L; x++) { - s << v[x] << ", "; - } - return s; + return (s << std::span {&v[0], L}); + } + + template + std::ostream & + operator<<(std::ostream & s, const array & v) + { + return (s << std::span {v}); + } + + template + std::ostream & + operator<<(std::ostream & s, const vector & v) + { + return (s << std::span {v}); } inline std::ostream & @@ -36,4 +55,13 @@ namespace std { } } +template +std::string +streamed_string(const T & v) +{ + std::stringstream ss; + ss << v; + return ss.str(); +} + #define CLOG(x) std::clog << #x " : " << x << "\n"; -- cgit v1.2.3