Advertisement
gurenko

Untitled

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