-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.h
53 lines (45 loc) · 1.69 KB
/
debug.h
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
#ifndef CPP_H_
#define CPP_H_
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
//One and the same thing
#define dbg(...){__Tushar_Garg__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
return out<<"("<<x.first<<","<<x.second<<")";
}
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const unordered_map<Arg1,Arg2> &a) {
out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
template <typename Arg1>
void __Tushar_Garg__(const string name, Arg1&& arg1){
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __Tushar_Garg__(const string names, Arg1&& arg1, Args&&... args){
const string name = names.substr(0,names.find(','));
cerr<<name<<" : "<<arg1<<" | ";
__Tushar_Garg__(names.substr(1+(int)name.size()), args...);
}
#endif