cs-mshah

colour debug template

Jun 24th, 2021
597
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // colout print
  2. template <class T1, class T2>
  3. ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  4.   return os << '{' << p.first << ", " << p.second << '}';
  5. }
  6.  
  7. template <class T, class = decltype(begin(declval<T>())),
  8.           class = enable_if_t<!is_same<T, string>::value>>
  9. ostream &operator<<(ostream &os, const T &c) {
  10.   os << '[';
  11.   for (auto it = begin(c); it != end(c); ++it)
  12.     os << (it == begin(c) ? "" : ", ") << *it;
  13.   return os << ']';
  14. }
  15.  
  16. #define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
  17. #define _FE_1(_CALL, x) _CALL(x)
  18. #define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
  19. #define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
  20. #define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
  21. #define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
  22. #define _FE_6(_CALL, x, ...) _CALL(x) _FE_5(_CALL, __VA_ARGS__)
  23. #define FOR_EACH_MACRO(MACRO, ...)                                             \
  24.   _NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1)              \
  25.   (MACRO, __VA_ARGS__)
  26. #define watch(x) cerr << "\033[1;32m" #x " = \033[1;34m" << (x) << "\033[0m; ";
  27. #define dbg(...)                                                             \
  28.   cerr << "\033[2;31mLine " << __LINE__ << ": \033[0;m";                       \
  29.   FOR_EACH_MACRO(watch, __VA_ARGS__)                                           \
  30.   cerr << "\n"
RAW Paste Data