-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.h
More file actions
69 lines (57 loc) · 1.96 KB
/
debug.h
File metadata and controls
69 lines (57 loc) · 1.96 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
#include <bits/stdc++.h>
using namespace std;
// ------------------------------------------------------------------------------------
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p)
{
return os << "(" << p.first << ", " << p.second << ")";
}
template<typename A, typename B, typename C> ostream &operator<<(ostream &os, const tuple<A, B, C> &t)
{
return os << "(" << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ")";
}
template<typename A, typename B, typename C, typename D> ostream &operator<<(ostream &os, const tuple<A, B, C, D> &t)
{
return os << "(" << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ", " << get<3>(t) << ")";
}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type >::type> ostream &operator<<(ostream &os, const T_container &v)
{
os << '{';
string sep;
for(const T &x: v)
os << sep << x, sep = ", ";
return os << '}';
}
// ------------------------------------------------------------------------------------
template<typename T> void debug_out(string s, T t)
{
cout << "[" << s << ": " << t << "]\n";
}
template<typename T, typename...U> void debug_out(string s, T t, U...u)
{
int w = 0, c = 0;
while(w < (int) s.size())
{
if(s[w] == '(' or s[w] == '{' or s[w] == '[') c++;
if(s[w] == ')' or s[w] == '}' or s[w] == ']') c--;
if(!c and s[w] == ',') break;
w++;
}
cout << "[" << s.substr(0, w) << ": " << t << "] ";
debug_out(s.substr(w + 2, (int) s.size() - w - 1), u...);
}
// ------------------------------------------------------------------------------------
template<typename T> string bin(T x)
{
if(x == T(0))
return "0";
string res = "";
while(x)
{
res += char('0' + (x & 1));
x /= 2;
}
reverse(res.begin(), res.end());
return res;
}
// ------------------------------------------------------------------------------------
#define dbg(Z...) debug_out(#Z, Z)