Advertisement
giGii

print cont

Sep 4th, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4.  
  5. using namespace std;
  6.  
  7. template<typename ContainerType>
  8. ostream& Print(ostream& output_stream, const ContainerType& container) {
  9.     if (container.size()) {
  10.         int length = container.size() - 1;
  11.         for (const auto& item : container) {
  12.             output_stream << item;
  13.  
  14.             if (!length) {
  15.                 break;
  16.             }
  17.             output_stream << ", ";
  18.             --length;
  19.         }
  20.     }
  21.  
  22.     return output_stream;
  23. }
  24.  
  25. using namespace std;
  26. template <typename Type>
  27. ostream& operator<<(ostream& out, const vector<Type>& container) {
  28.     return Print(out, container);
  29. }
  30.  
  31. template <typename Type>
  32. ostream& operator<<(ostream& out, const set<Type>& container) {
  33.     return Print(out, container);
  34. }
  35.  
  36. int main() {
  37.    
  38.     const vector<int> ages = {10, 5, 2, 12};
  39.     cout << ages << endl;
  40.    
  41.     const set<string> cats = {"Мурка"s, "Белка"s, "Георгий"s, "Рюрик"s};
  42.     cout << cats << endl;
  43.    
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement