This repository has been archived by the owner on Mar 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebugger.cpp
63 lines (62 loc) · 2.02 KB
/
Debugger.cpp
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
#include <bits/stdc++.h>
using namespace std;
namespace debugger {
#ifdef DEBUG
template <typename T> void __print_var(string_view name, const T &x) {
std::cerr << name << " = " << x;
}
void __print_var(string_view name, const string &x) {
std::cerr << name << " = \"" << x << "\"";
}
void __print_var(string_view name, const char &x) {
std::cerr << name << " = \'" << x << "\'";
}
template <typename T> void __print_var(string_view name, const vector<T> &x) {
std::cerr << name << " = ";
bool is_first = true;
for (auto &ele : x)
std::cerr << (is_first ? (is_first = false, "[") : ", ") << ele;
std::cerr << "]";
}
template <typename T> void __print_var(string_view name, const set<T> &x) {
std::cerr << name << " = ";
bool is_first = true;
for (auto &ele : x)
std::cerr << (is_first ? (is_first = false, "{") : ", ") << ele;
std::cerr << "}";
}
template <typename K, typename V>
void __print_var(string_view name, const map<K, V> &x) {
std::cerr << name << " = ";
bool is_first = true;
for (auto &[k, v] : x)
std::cerr << (is_first ? (is_first = false, "{") : ", ") << "(" << k
<< ": " << v << ")";
std::cerr << "}";
}
template <typename T> void __log(string_view name, const T &x) {
__print_var(name, x);
std::cerr << '\n';
}
template <typename T, typename... Ts>
void __log(string_view name, const T &x, const Ts &...others) {
size_t pos = name.find(',');
__print_var(name.substr(0, pos), x);
std::cerr << ", ";
__log(name.substr(pos + 1), others...);
}
#define LOG(args...) \
{ \
std::cerr << "line " << __LINE__ << ": " << __func__ << "(): "; \
__log(#args, ##args); \
}
#else
#define LOG(...)
#endif
} // namespace debugger
using namespace debugger;
auto main() -> int {
string s;
s = "helloworld";
LOG(s);
}