From d2d5b3b5ca9ae0b13c347ae77f6abd15fdb44390 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Wed, 1 Nov 2023 21:03:55 +0200 Subject: Added a debug.h which contains all nesccseary functions to debug my code --- algo/debug.h | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) (limited to 'algo') diff --git a/algo/debug.h b/algo/debug.h index f7b1a0b..d63f896 100644 --- a/algo/debug.h +++ b/algo/debug.h @@ -1,30 +1,6 @@ #include using namespace std; -using ll = long long; -using pii = pair; -using vpii = vector; -using vi = vector; -using vll = vector; -using mpii = map; -using mpll = map; -using db = long double; - -#define pb push_back -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define lb lower_bound -#define ub upper_bound -#define make_unique(x) \ - sort(all((x))); \ - (x).resize(unique(all((x))) - (x).begin()) -#define ceil(a, b) ((a) + (b)-1) / (b) - -const int mod = (int)1e9 + 7; -const db pi = acos((db)-1); -const int dx[4]{1, 0, -1, 0}; -const int dy[4]{0, 1, 0, -1}; - template ostream &operator<<(ostream &os, const pair &p); template ostream &operator<<(ostream &os, const vector &vec); @@ -113,11 +89,18 @@ ostream &operator<<(ostream &os, const unordered_set &s) { return os; } -void debug_out() { cerr << endl; } +template +void debug_out(const std::string_view names, const Ts &...ts) { + size_t start = 0; + + const auto print_single = [&names](size_t start, const auto &value) { + const auto end = names.find(',', start + 1); + std::cerr << names.substr(start, end - start) << " = " << value << '\n'; + + return end + 2; + }; -template void debug_out(head h, tail... t) { - cerr << h << '\n'; - debug_out(t...); + ((start = print_single(start, ts)), ...); } -#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):\n", debug_out(__VA_ARGS__) +#define dbg(...) debug_out(#__VA_ARGS__, __VA_ARGS__) -- cgit v1.2.3