-
Notifications
You must be signed in to change notification settings - Fork 7
/
debugger.sublime-snippet
91 lines (80 loc) · 2.35 KB
/
debugger.sublime-snippet
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
<snippet>
<content><![CDATA[
#if DEBUG && !ONLINE_JUDGE
// Author : Nikhil Garg
#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 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 debug(args...) // Just strip off all debug tokens
#endif
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>debugger</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>