-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.h
105 lines (93 loc) · 2.52 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
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
105
#ifndef SLOPE_DEBUG_H_
#define SLOPE_DEBUG_H_
#include <errno.h>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#ifdef SLOPE_DEBUG
#define deb(x) std::cout << #x << ": " << (x) << std::endl
# define deb2(x, y) std::cout << #x << ": " << (x) << ", " << #y << ": " << (y) << std::endl
# define debout(x) std::cout << x << std::endl
# define debline() std::cout << std::endl
#define infoout(x) std::cout << "[INFO] " << x << std::endl
#else
#define NOOP \
do { \
} while (0)
#define deb(x) NOOP
#define deb2(x, y) NOOP
#define debout(x) NOOP
#define debline() NOOP
#define infoout(x) NOOP
#endif // SLOPE_DEBUG
template<typename T, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T, T2>& p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template<typename T, typename T2>
std::ostream& operator<<(std::ostream& os, const std::map<T, T2>& mp) {
os<< "{";
int first = 1;
for(const auto& it: mp) {
if(!first) {
os << ", ";
}
first = 0;
os << it.first << ": " << it.second;
}
os << "}";
return os;
}
template<typename T, typename Alloc = std::allocator<T>>
std::ostream& operator<<(std::ostream& os, const std::vector<T, Alloc>& v) {
os<< "[";
int first = 1;
for(const auto& it: v) {
if(!first) {
os << ", ";
}
first = 0;
os << it;
}
os << "]";
return os;
}
template<typename T, typename Alloc = std::allocator<T>>
std::ostream& operator<<(std::ostream& os, const std::set<T, Alloc>& v) {
os<< "{";
int first = 1;
for(const auto& it: v) {
if(!first) {
os << ", ";
}
first = 0;
os << it;
}
os << "}";
return os;
}
#define assert_p(cond, msg) \
do { \
if (!(cond)) { \
perror(msg); \
std::abort(); \
} \
} while (false);
#define assert_ibv_completion(status) \
do { \
if (status) { \
std::cerr << "[" << __FILE__ << ":" << __LINE__ << " " << __func__ \
<< "] " << ibv_wc_status_str(status) << std::endl; \
} \
} while (false)
#define prompt(x) do { \
std::string _; \
std::cout << (x) << std::endl; \
std::cin >> _; \
} while(false);
template<typename... Args>
struct Typer;
#endif // SLOPE_DEBUG_H_