fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <tuple>
  5.  
  6. // mecroses:
  7.  
  8. #define watch(x) debug && std::cout << #x << " = " << x
  9. #define watchln(x) watch(x) << std::endl
  10. #define watchsp(x) watch(x) << " "
  11.  
  12. // printing of containers:
  13.  
  14. // printing a range for two iterators:
  15. template<class Iterator> std::ostream& print_range(std::ostream& os, Iterator begin, Iterator end) {
  16. os << "{";
  17. for (auto it = begin; it != end; os << *it++)
  18. if (it != begin) os << ", ";
  19. return os << "}";
  20. }
  21.  
  22. // printing vector:
  23. template<class X> std::ostream& operator<<(std::ostream& os, const std::vector<X>& vec) {
  24. return print_range(os, vec.begin(), vec.end());
  25. }
  26.  
  27. // printing set
  28. template<class X> std::ostream& operator<<(std::ostream& os, const std::set<X>& set) {
  29. return print_range(os, set.begin(), set.end());
  30. }
  31.  
  32. // printing pair:
  33. template<class X, class T> std::ostream& operator<<(std::ostream& os, const std::pair<X,T>& pr) {
  34. return os << "{" << pr.first << ", " << pr.second << "}";
  35. }
  36.  
  37. // enable debug:
  38.  
  39. const int debug = 1;
  40.  
  41. // examples:
  42.  
  43. int main() {
  44. std::vector<int> arr{1,2,3};
  45. watchln(arr);
  46.  
  47. std::vector<std::set<int>> vector_of_sets{{1,2,2},{2,1,3},{3,3,3}};
  48. watchln(vector_of_sets);
  49.  
  50. std::vector<std::vector<int>> vector_of_vectors{{1,2,2},{2,1,3},{3,3,3}};
  51. watchln(vector_of_vectors);
  52.  
  53. std::pair<int,int> pair(1,2);
  54. watchln(pair);
  55. }
Success #stdin #stdout 0s 4432KB
stdin
Standard input is empty
stdout
arr = {1, 2, 3}
vector_of_sets = {{1, 2}, {1, 2, 3}, {3}}
vector_of_vectors = {{1, 2, 2}, {2, 1, 3}, {3, 3, 3}}
pair = {1, 2}