fork(9) download
  1. #include<iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. /* -------------------This is the part you need to copy ----------------------*/
  9.  
  10. #if DEBUG && !ONLINE_JUDGE
  11.  
  12. // Author : Nikhil Garg
  13.  
  14. #define debug(args...) (Debugger()) , args
  15.  
  16. class Debugger
  17. {
  18. public:
  19. Debugger(const std::string& _separator = ", ") :
  20. first(true), separator(_separator){}
  21.  
  22. template<typename ObjectType>
  23. Debugger& operator , (const ObjectType& v)
  24. {
  25. if(!first)
  26. std::cerr << separator;
  27. std::cerr << v;
  28. first = false;
  29. return *this;
  30. }
  31. ~Debugger() { std::cerr << endl;}
  32.  
  33. private:
  34. bool first;
  35. std::string separator;
  36. };
  37.  
  38. template <typename T1, typename T2>
  39. inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
  40. {
  41. return os << "(" << p.first << ", " << p.second << ")";
  42. }
  43.  
  44. template<typename T>
  45. inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
  46. {
  47. bool first = true;
  48. os << "[";
  49. for(unsigned int i = 0; i < v.size(); i++)
  50. {
  51. if(!first)
  52. os << ", ";
  53. os << v[i];
  54. first = false;
  55. }
  56. return os << "]";
  57. }
  58.  
  59. template<typename T>
  60. inline std::ostream &operator << (std::ostream & os,const std::set<T>& v)
  61. {
  62. bool first = true;
  63. os << "[";
  64. for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
  65. {
  66. if(!first)
  67. os << ", ";
  68. os << *ii;
  69. first = false;
  70. }
  71. return os << "]";
  72. }
  73.  
  74. template<typename T1, typename T2>
  75. inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v)
  76. {
  77. bool first = true;
  78. os << "[";
  79. for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
  80. {
  81. if(!first)
  82. os << ", ";
  83. os << *ii ;
  84. first = false;
  85. }
  86. return os << "]";
  87. }
  88.  
  89. #else
  90. #define debug(args...) // Just strip off all debug tokens
  91. #endif
  92.  
  93. /*-------------------------------Stop here---------------------------------*/
  94.  
  95. int main()
  96. {
  97.  
  98. // Usage howto and testing debug macro
  99.  
  100. int T= 1;
  101. debug(T, 2, 10, "String");
  102. vector<int> A;
  103. set<double> s;
  104. s.insert(12.3); s.insert(20.98);
  105. debug("Vector A", A, "Set S", s);
  106. pair<int, string> P(41, "Nikhil");
  107. pair<double, pair<int, string> > PP(12.2, P);
  108. debug(PP);
  109. map<int, int> freq;
  110. freq[21] = 3;
  111. freq[89] = 5;
  112. debug(freq);
  113.  
  114. int B[20];
  115. B[0] = 123; B[1] = 232; B[2] = 92;
  116. typedef vector<int> VI;
  117. debug(VI(B, B+3));
  118.  
  119. return 0;
  120. }
Success #stdin #stdout 0s 4540KB
stdin
Standard input is empty
stdout
Standard output is empty