Praktikum_mf

Задача 5

Dec 14th, 2021
1,850
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 <set>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. template <typename Container>
  8. void Print(ostream& out, const Container& container) {
  9.     bool is_first = true;
  10.     for (const auto& element : container) {
  11.         if (!is_first) {
  12.             out << ", "s;
  13.         }
  14.         is_first = false;
  15.         out << element;
  16.     }
  17. }
  18.  
  19. template <typename Element>
  20. ostream& operator<<(ostream& out, const vector<Element>& container) {
  21.     out << '[';
  22.     Print(out, container);
  23.     out << ']';
  24.     return out;
  25. }
  26.  
  27. template <typename Element>
  28. ostream& operator<<(ostream& out, const set<Element>& container) {
  29.     out << '{';
  30.     Print(out, container);
  31.     out << '}';
  32.     return out;
  33. }
  34.  
  35. int main() {
  36.     const set<string> cats = {"Мурка"s, "Белка"s, "Георгий"s, "Рюрик"s};
  37.     cout << cats << endl;
  38.  
  39.     const vector<int> ages = {10, 5, 2, 12};
  40.     cout << ages << endl;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment