-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.h
More file actions
110 lines (95 loc) · 2.46 KB
/
debug.h
File metadata and controls
110 lines (95 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
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
template <typename T, typename U>
string to_string(pair<T, U> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(const char c) { return to_string((string)"" + c); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename T>
string to_string(T v) {
bool first = true;
string res = "{";
for (const auto& x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename T>
string to_string(priority_queue<T> heap) {
bool first = true;
string res = "{";
while ((int) heap.size()) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(heap.top());
heap.pop();
}
res += "}";
return res;
}
template <typename T>
string to_string(priority_queue<T, vector<T>, greater<T>> heap) {
bool first = true;
string res = "{";
while ((int) heap.size()) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(heap.top());
heap.pop();
}
res += "}";
return res;
}
template <typename T, typename U>
string to_string(pair<T, U> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename ... Ts>
string to_string(const Ts& ... ts) {
stringstream ss;
const char* sep = "";
((static_cast<void>(ss << sep << ts), sep = ", "), ...);
return ss.str();
}
template <typename... Args>
string to_string(const std::tuple<Args...>& t) {
string res = "(";
apply([&](const auto&... ts) { res += to_string(ts...); }, t);
res += ")";
return res;
}
void debug_out() { cout << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << " " << to_string(H); debug_out(T...); }
#ifdef DANIEL_DEBUG_TEMPLATE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif