summaryrefslogtreecommitdiff
path: root/lib/stream_support.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stream_support.h')
-rw-r--r--lib/stream_support.h38
1 files changed, 33 insertions, 5 deletions
diff --git a/lib/stream_support.h b/lib/stream_support.h
index 57d82a1..f21622a 100644
--- a/lib/stream_support.h
+++ b/lib/stream_support.h
@@ -4,8 +4,10 @@
#include <glm/glm.hpp>
#include <iostream>
#include <maths.h>
+#include <source_location>
#include <span>
#include <sstream>
+#include <tuple>
#include <type_traits>
template<typename S>
@@ -16,14 +18,14 @@ concept NonStringIterableCollection
namespace std {
std::ostream &
- operator<<(std::ostream & s, const NonStringIterableCollection auto & v)
+ operator<<(std::ostream & s, const NonStringIterableCollection auto & collection)
{
s << '(';
- for (const auto & i : v) {
- if (&i != &*v.begin()) {
+ for (size_t nth {}; const auto & element : collection) {
+ if (nth++) {
s << ", ";
}
- s << i;
+ s << element;
}
return s << ')';
}
@@ -49,6 +51,22 @@ namespace std {
return (s << '(' << v.first << ", " << v.second << ')');
}
+ namespace {
+ template<typename... T, size_t... Idx>
+ std::ostream &
+ printTuple(std::ostream & s, const std::tuple<T...> & v, std::integer_sequence<size_t, Idx...>)
+ {
+ return ((s << (Idx ? ", " : "") << std::get<Idx>(v)), ...);
+ }
+ }
+
+ template<typename... T>
+ std::ostream &
+ operator<<(std::ostream & s, const std::tuple<T...> & v)
+ {
+ return printTuple(s << '{', v, std::make_index_sequence<sizeof...(T)>()) << '}';
+ }
+
inline std::ostream &
operator<<(std::ostream & s, const Arc & arc)
{
@@ -75,4 +93,14 @@ streamed_string(const T & v)
return std::move(ss).str();
}
-#define CLOG(x) std::cerr << __LINE__ << " : " #x " : " << x << "\n";
+namespace {
+ template<typename T>
+ void
+ clogImpl(const T & value, const std::string_view name,
+ const std::source_location loc = std::source_location::current())
+ {
+ std::cerr << loc.line() << " : " << name << " : " << value << "\n";
+ }
+}
+
+#define CLOG(x) clogImpl(x, #x)