From 5a0b3927a33807cca4c77c40eb873f8a3b51b0b0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 29 Apr 2023 19:07:11 +0100 Subject: Drop .hpp for header only things Half of them acquired a .cpp part anyway --- lib/stream_support.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 lib/stream_support.h (limited to 'lib/stream_support.h') diff --git a/lib/stream_support.h b/lib/stream_support.h new file mode 100644 index 0000000..7fb256c --- /dev/null +++ b/lib/stream_support.h @@ -0,0 +1,86 @@ +#pragma once + +#include "enumDetails.h" +#include +#include +#include +#include +#include +#include + +template +concept stringlike = requires(const S & s) { s.substr(0); }; +template +concept spanable = std::is_constructible_v, T> && ! +stringlike && !std::is_same_v, T>; + +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) + { + return (s << std::span {&m[0], L}); + } + + template + std::ostream & + operator<<(std::ostream & s, const glm::vec & v) + { + return (s << std::span {&v[0], L}); + } + + template + std::ostream & + operator<<(std::ostream & s, const T & v) + { + return (s << std::span {v}); + } + + template + std::ostream & + operator<<(std::ostream & s, const std::pair & v) + { + return (s << '(' << v.first << ", " << v.second << ')'); + } + + inline std::ostream & + operator<<(std::ostream & s, const Arc & arc) + { + return s << arc.first << " ↺ " << arc.second; + } + + template + concept IsEnum = std::is_enum_v; + + template + inline std::ostream & + operator<<(std::ostream & s, const E & e) + { + return s << EnumTypeDetails::typeName << "::" << EnumDetails::to_string(e).value(); + } +} + +template +std::string +streamed_string(const T & v) +{ + std::stringstream ss; + ss << v; + return std::move(ss).str(); +} + +#define CLOG(x) std::cerr << __LINE__ << " : " #x " : " << x << "\n"; -- cgit v1.2.3