Skip to content

Instantly share code, notes, and snippets.

@dabasajay
Created March 2, 2021 11:09
Show Gist options
  • Save dabasajay/f07d048f6ec258d381ece51734b2b0ca to your computer and use it in GitHub Desktop.
Save dabasajay/f07d048f6ec258d381ece51734b2b0ca to your computer and use it in GitHub Desktop.
others/ | desc: Debug template
#define ll long long
#define pi pair<ll, ll>
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T, typename S> ostream& operator<<(ostream& os, const pair<T, S>& p) {os << "(" << p.first << ", " << p.second << ")";return os;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {os << "[";for (auto i : v) os << i << " ";os << "\b]";return os;}
template <typename T> ostream& operator<<(ostream& os, const multiset<T>& s) {os << "{";for (auto i : s) os << i << " ";os << "\b}";return os; }
template <typename T> ostream& operator<<(ostream& os, const set<T>& s) {os << "{";for (auto i : s) os << i << " ";os << "\b}";return os; }
template <typename T> ostream& operator<<(ostream& os, const unordered_set<T>& s) {os << "{";for (auto i : s) os << i << " ";os << "\b}";return os; }
template <typename T1, typename T2> ostream& operator<<(ostream& os, const map<T1, T2>& s) {for (auto i : s) os << i << endl;return os; }
template <typename T1, typename T2> ostream& operator<<(ostream& os, const unordered_map<T1, T2>& s) {for (auto i : s) os << i << endl;return os; }
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment