Last active
August 18, 2020 07:25
-
-
Save IMelker/a0ef2567eb9dd92715bd4ff5c5f7aa32 to your computer and use it in GitHub Desktop.
Cpp Tricks
This file contains hidden or 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
// determining array size | |
template <typename T, auto N> | |
char (&ArraySizeHelper(T (&array)[N]))[N]; | |
#define arraysize(array) (sizeof(ArraySizeHelper(array))) | |
// convert defined value to string | |
#define expect(expr) if(!expr) cerr << "Assertion " << #expr \ | |
" failed at " << __FILE__ << ":" << __LINE__ << endl; | |
#define stringify(x) #x | |
#define tostring(x) stringify(x) | |
#define MAGIC_CONSTANT 314159 | |
cout << "Value of MAGIC_CONSTANT=" << tostring(MAGIC_CONSTANT); | |
// dump container content | |
#define dbg(v) copy(v.begin(), v.end(), ostream_iterator<typeof(*v.begin())>(cout, " ")) | |
// debug for exact container | |
#ifdef NDEBUG | |
#define DEBUG(var) | |
#else | |
#define DEBUG(var) { std::cout << #var << ": " << (var) << std::endl; } | |
#endif | |
template <typename T1, typename T2> | |
std::ostream& operator<< (std::ostream& out, const std::map<T1,T2> &M) { | |
out << "{ "; | |
for (auto item:M) out << item.first << "->" << item.second << ", "; | |
out << "}"; | |
return out; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment