-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug.hpp
More file actions
124 lines (102 loc) · 3.02 KB
/
debug.hpp
File metadata and controls
124 lines (102 loc) · 3.02 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <bits/stdc++.h>
namespace debug {
namespace detail {
template <typename Tuple, size_t... I>
void PrintTuple(std::ostream& os, Tuple tuple, std::index_sequence<I...>) {
os << '(';
(..., (operator<<(os, I == 0 ? "" : ", "), operator<<(os, std::get<I>(tuple))));
os << ')';
}
} // namespace detail
template <typename ... T>
std::ostream& operator<<(std::ostream &os, std::tuple<T...> tuple) {
detail::PrintTuple(os, std::forward<decltype(tuple)>(tuple), std::make_index_sequence<sizeof...(T)>{});
return os;
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, std::pair<T, U> pair) {
return os << '(' << pair.first << ", " << pair.second << ')';
}
std::ostream& operator<<(std::ostream& os, std::vector<bool> vector) {
os << '[';
for (auto sep = ""; auto f : vector) {
os << std::exchange(sep, " ") << "01"[f];
}
return os << ']';
}
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vector) {
os << '[';
for (auto sep = ""; auto f : vector) {
os << std::exchange(sep, " ") << f;
}
return os << ']';
}
template <typename T, std::size_t N>
std::ostream& operator<<(std::ostream& os, std::array<T, N> array) {
os << '[';
for (auto sep = ""; auto f : array) {
os << std::exchange(sep, " ") << f;
}
return os << ']';
}
template <typename T>
std::ostream& operator<<(std::ostream& os, std::set<T> set) {
os << '{';
for (auto sep = ""; auto f : set) {
os << std::exchange(sep, " ") << f;
}
return os << '}';
}
template <typename T>
std::ostream& operator<<(std::ostream& os, std::multiset<T> multiset) {
os << '{';
for (auto sep = ""; auto f : multiset) {
os << std::exchange(sep, " ") << f;
}
return os << '}';
}
template <typename T>
std::ostream& operator<<(std::ostream& os, std::unordered_set<T> unorderedSet) {
os << '{';
for (auto sep = ""; auto f : unorderedSet) {
os << std::exchange(sep, " ") << f;
}
return os << '}';
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, std::map<T, U> map) {
os << '{';
for (auto sep = ""; auto [k, v] : map) {
os << std::exchange(sep, " ") << k << ": " << v;
}
return os << '}';
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, std::unordered_map<T, U> uMap) {
os << '{';
for (auto sep = ""; auto [k, v] : uMap) {
os << std::exchange(sep, " ") << k << ": " << v;
}
return os << '}';
}
std::ostream& operator<<(std::ostream& os, std::integral auto&& x) {
return os << x;
}
std::ostream& operator<<(std::ostream& os, bool f) {
return os << (f ? "True" : "False");
}
std::ostream& operator<<(std::ostream& os, const char *str) {
return os << std::string(str);
}
void Print() {
std::cerr << std::endl;
}
template <typename Head, typename... Tail>
void Print(Head head, Tail ... tail) {
std::cerr << " ";
operator<<(std::cerr, std::forward<Head>(head));
Print(std::forward<Tail>(tail)...);
}
} // namespace debug
#define dbg(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug::Print(__VA_ARGS__)