-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.h
More file actions
41 lines (39 loc) · 1.28 KB
/
debug.h
File metadata and controls
41 lines (39 loc) · 1.28 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
#include <bits/stdc++.h>
using namespace std;
#define db(...) \
cerr << "__debug__ " << __LINE__ << " "; \
debug::ZZ(#__VA_ARGS__, __VA_ARGS__);
namespace debug
{
template <typename Ostream, typename X, typename Y>
inline typename enable_if<is_same<Ostream, ostream>::value, Ostream &>::type operator<<(Ostream &out, pair<X, Y> const &p)
{
out << '[' << p.first << ", " << p.second << ']';
return out;
}
template <typename Ostream, typename Cont>
inline typename enable_if<is_same<Ostream, ostream>::value, Ostream &>::type operator<<(Ostream &out, const Cont &x)
{
out << "{";
for (auto &y : x)
out << " " << y;
out << " }";
return out;
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
while (*name == ',' || *name == ' ')
name++;
std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&...args)
{
while (*names == ',' || *names == ' ')
names++;
const char *comma = strchr(names + 1, ',');
std::cerr.write(names, comma - names) << " = " << arg1 << ", ";
ZZ(comma, args...);
}
}