Skip to content

Instantly share code, notes, and snippets.

@CompewterTutor
Created January 30, 2025 22:49
Show Gist options
  • Select an option

  • Save CompewterTutor/541f8440efdc3305f4f87c02cdd2e698 to your computer and use it in GitHub Desktop.

Select an option

Save CompewterTutor/541f8440efdc3305f4f87c02cdd2e698 to your computer and use it in GitHub Desktop.
Leetcode C++ Debugging
//// OUTPUT MACROS FOR DEBUGGING
#define LINE0 9
#define cout_line (cout << "line " << __LINE__ - LINE0 << ": ")
#define vout(v) #v << " = " << (v)
#define print1(v) cout_line << vout(v) << endl
#define print2(v1, v2) cout_line << vout(v1) << ", " << vout(v2) << endl
#define print3(v1, v2, v3) cout_line << vout(v1) << ", " << vout(v2) << ", " << vout(v3) << endl
#define print4(v1, v2, v3, v4) cout_line << vout(v1) << ", " << vout(v2) << ", " << vout(v3) << ", " << vout(v4) << endl
#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define print(...) GET_MACRO(__VA_ARGS__, print4, print3, print2, print1)(__VA_ARGS__) //COMMENT OUT BEFORE SUBMITTING
//#define print(...) //UNCOMMENT BEFORE SUBMITTING
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x);
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
return os << p.first << ":" << p.second;
}
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
os << "[";
bool first = true;
for(auto const& y : x) {
if (!first) os << ", ";
os << y;
first = false;
}
return os << "]";
}
//// CODE STARTS HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment