summaryrefslogtreecommitdiff
path: root/lib/stream_support.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stream_support.hpp')
-rw-r--r--lib/stream_support.hpp52
1 files changed, 40 insertions, 12 deletions
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 <glm/glm.hpp>
#include <iostream>
#include <maths.h>
+#include <span>
+#include <sstream>
namespace std {
+ template<typename T, std::size_t L>
+ std::ostream &
+ operator<<(std::ostream & s, const span<const T, L> v)
+ {
+ s << '(';
+ for (const auto & i : v) {
+ if (&i != &v.front())
+ s << ", ";
+ s << i;
+ }
+ return s << ')';
+ }
+
template<glm::length_t L, glm::length_t R, typename T, glm::qualifier Q>
std::ostream &
operator<<(std::ostream & s, const glm::mat<L, R, T, Q> & 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<glm::length_t L, typename T, glm::qualifier Q>
std::ostream &
operator<<(std::ostream & s, const glm::vec<L, T, Q> & v)
{
- for (int x = 0; x < L; x++) {
- s << v[x] << ", ";
- }
- return s;
+ return (s << std::span {&v[0], L});
+ }
+
+ template<typename T, std::size_t L>
+ std::ostream &
+ operator<<(std::ostream & s, const array<T, L> & v)
+ {
+ return (s << std::span {v});
+ }
+
+ template<typename T>
+ std::ostream &
+ operator<<(std::ostream & s, const vector<T> & v)
+ {
+ return (s << std::span {v});
}
inline std::ostream &
@@ -36,4 +55,13 @@ namespace std {
}
}
+template<typename T>
+std::string
+streamed_string(const T & v)
+{
+ std::stringstream ss;
+ ss << v;
+ return ss.str();
+}
+
#define CLOG(x) std::clog << #x " : " << x << "\n";