Skip to content

Instantly share code, notes, and snippets.

@Teemu
Created April 17, 2016 15:43
Show Gist options
  • Save Teemu/ada2e261557cba25c5c92c6fc80183ec to your computer and use it in GitHub Desktop.
Save Teemu/ada2e261557cba25c5c92c6fc80183ec to your computer and use it in GitHub Desktop.
C++ debug macros
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