summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-01-03 18:28:10 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-01-03 18:28:10 +0000
commitb1add835864a5907dc5a674f7eee2f3db038f704 (patch)
treec2ab5ee08422f5a9bad406e4f2b28534fb3e9cb9 /lib
parentAdd transform_array (diff)
downloadilt-b1add835864a5907dc5a674f7eee2f3db038f704.tar.bz2
ilt-b1add835864a5907dc5a674f7eee2f3db038f704.tar.xz
ilt-b1add835864a5907dc5a674f7eee2f3db038f704.zip
More complete and tested stream output support
Diffstat (limited to 'lib')
-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";