-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.h
More file actions
79 lines (64 loc) · 2.46 KB
/
printer.h
File metadata and controls
79 lines (64 loc) · 2.46 KB
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
77
78
79
#pragma once
#include <iostream>
#include <sstream>
#include <vector>
#include <tuple>
#include <utility>
#include <set>
#include <map>
#include <deque>
#include <list>
namespace Smoren::Tools {
template <typename Collection>
std::string join(const Collection& collection, const std::string& delimiter);
template <typename First, typename Second>
std::ostream& operator <<(std::ostream& stream, const std::pair<First, Second>& p);
template <typename Key, typename Value>
std::ostream& operator <<(std::ostream& stream, const std::map<Key, Value>& m);
template <typename Value>
std::ostream& operator <<(std::ostream& stream, const std::vector<Value>& m);
template <typename Value>
std::ostream& operator <<(std::ostream& stream, const std::set<Value>& m);
template <typename Value>
std::ostream& operator <<(std::ostream& stream, const std::deque<Value>& m);
template <typename Value>
std::ostream& operator <<(std::ostream& stream, const std::list<Value>& m);
template <typename Collection>
std::string join(const Collection& collection, const std::string& delimiter) {
bool isFirst = true;
std::stringstream ss;
for(auto& item : collection) {
if(!isFirst) {
ss << delimiter;
} else {
isFirst = false;
}
ss << item;
}
return ss.str();
}
template <typename First, typename Second>
std::ostream& operator <<(std::ostream& stream, const std::pair<First, Second>& p) {
return stream << p.first << ": " << p.second;
}
template <typename Key, typename Value>
std::ostream& operator <<(std::ostream& stream, const std::map<Key, Value>& m) {
return stream << "{" << join(m, ", ") << "}";
}
template <typename Value>
std::ostream& operator <<(std::ostream& stream, const std::vector<Value>& m) {
return stream << "[" << join(m, ", ") << "]";
}
template <typename Value>
std::ostream& operator <<(std::ostream& stream, const std::set<Value>& m) {
return stream << "(" << join(m, ", ") << ")";
}
template <typename Value>
std::ostream& operator <<(std::ostream& stream, const std::deque<Value>& m) {
return stream << "[" << join(m, ", ") << "]";
}
template <typename Value>
std::ostream& operator <<(std::ostream& stream, const std::list<Value>& m) {
return stream << "[" << join(m, ", ") << "]";
}
}