summaryrefslogtreecommitdiff
path: root/lib/stream_support.hpp
blob: 2ab2f9d72b716847ea9a1a9e3030cab174c56905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once

#include "enumDetails.hpp"
#include <glm/glm.hpp>
#include <iostream>
#include <maths.h>
#include <span>
#include <sstream>
#include <type_traits>

template<typename T>
concept spanable = std::is_constructible_v<std::span<const typename T::value_type>, T> && !
std::is_same_v<char, std::decay_t<typename T::value_type>>;

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)
	{
		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)
	{
		return (s << std::span {&v[0], L});
	}

	template<spanable T>
	std::ostream &
	operator<<(std::ostream & s, const T & v)
	{
		return (s << std::span {v});
	}

	inline std::ostream &
	operator<<(std::ostream & s, const Arc & arc)
	{
		return s << arc.first << " ↺ " << arc.second;
	}

	template<typename E>
	concept IsEnum = std::is_enum_v<E>;

	template<IsEnum E>
	inline std::ostream &
	operator<<(std::ostream & s, const E & e)
	{
		return s << EnumTypeDetails<E>::typeName << "::" << EnumDetails<E>::to_string(e).value();
	}
}

template<typename T>
std::string
streamed_string(const T & v)
{
	std::stringstream ss;
	ss << v;
	return std::move(ss).str();
}

#define CLOG(x) std::cerr << #x " : " << x << "\n";