forked from jahid-hridoy/Code_Templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.h
More file actions
104 lines (91 loc) · 2.25 KB
/
debug.h
File metadata and controls
104 lines (91 loc) · 2.25 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
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define deb(args...) cerr << "[ " #args << " ] : " , debug(args);
#define debx(args...) (Debugger(" ")),args
#define debug(args...) (Debugger()) , args
class Debugger
{
public:
Debugger(const std::string& _separator = ", ") :
first(true), separator(_separator) {}
template<typename ObjectType>
Debugger& operator , (const ObjectType& v)
{
if (!first)
std::cerr << separator;
std::cerr << v;
first = false;
return *this;
}
~Debugger() { std::cerr << endl;}
private:
bool first;
std::string separator;
};
template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
{
return os << "(" << p.first << ", " << p.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os, const std::vector<T>& v)
{
bool first = true;
os << "[";
for (unsigned int i = 0; i < v.size(); i++)
{
if (!first)
os << ", ";
os << v[i];
first = false;
}
return os << "]";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os, const std::set<T>& v)
{
bool first = true;
os << "[";
for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
{
if (!first)
os << ", ";
os << *ii;
first = false;
}
return os << "]";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os, const std::multiset<T>& v)
{
bool first = true;
os << "[";
for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
{
if (!first)
os << ", ";
os << *ii;
first = false;
}
return os << "]";
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v)
{
bool first = true;
os << "[";
for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
{
if (!first)
os << ", ";
os << *ii ;
first = false;
}
return os << "]";
}
#else
#define deb(args...)
#define debx(args...)
#define debug(args...)
#endif