Created
April 17, 2016 15:43
-
-
Save Teemu/ada2e261557cba25c5c92c6fc80183ec to your computer and use it in GitHub Desktop.
C++ debug macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int PRINT_TIMES = 0; | |
#define PRINT(x) PRINT_TIMES++; if (PRINT_TIMES <= 40) {std::cout << #x << " = " << x << "\n";} | |
#define PRINT_VECTOR(x) PRINT_TIMES++; if (PRINT_TIMES <= 40){std::cout << #x << " = "; print_vector(x);} | |
template <typename T> | |
void print_vector(T &v) { | |
std::cout << "{"; | |
bool first_value = true; | |
for (auto i = v.begin(); i != v.end(); ++i) { | |
if (first_value) { | |
first_value = false; | |
} else { | |
std::cout << ", "; | |
} | |
std::cout << *i; | |
} | |
std::cout << "}\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment