nochnoikoshmar1
Feb 26th, 2023 (edited)
47
0
Never
This is comment for paste Задача 6
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template <typename Element, typename T>
  2. void Print(ostream &out, const map<Element, T> &container){
  3.     int count = 1;
  4.     for(const auto &[element,age] : container){
  5.         out << "("s << element << ", " << age << ")";
  6.         if(container.size() > count){
  7.             out << ", "s;
  8.             ++count;
  9.         }      
  10.     }
  11. }
  12. template <typename Element>
  13. void Print(ostream &out, const Element &container){
  14.     bool is_map = true;
  15.     for(const auto &element : container){
  16.         if(!is_map)
  17.             out << ", "s;        
  18.         is_map = false;
  19.         out << element;
  20.     }
  21. }
  22. template <typename Element>
  23. ostream &operator<<(ostream &out, const vector<Element> &container){
  24.     out << "["s;
  25.     Print(out, container);
  26.     out << "]"s;
  27.     return out;
  28. }
  29. template <typename Element>
  30. ostream &operator<<(ostream &out, const set<Element> &container){
  31.     out << "{"s;
  32.     Print(out, container);
  33.     out << "}"s;
  34.     return out;
  35. }
  36. template <typename Element, typename T>
  37. ostream &operator<<(ostream &out, const map<Element,T> &container){    
  38.     out << "<"s;
  39.     Print(out, container);
  40.     out << ">"s;
  41.     return out;
  42. }
  43. int main(){
  44.     setlocale(LC_ALL, "");
  45.     const set<string> cats = {"Мурка"s, "Белка"s, "Георгий"s, "Рюрик"s};
  46.     cout << cats << endl;
  47.     const vector<int> ages = {10, 5, 2, 12};
  48.     cout << ages << endl;
  49.     const map<string, int> cat_ages = {
  50.         {"Мурка"s, 10},
  51.         {"Белка"s, 5},
  52.         {"Георгий"s, 2},
  53.         {"Рюрик"s, 12}
  54.     };
  55.     cout << cat_ages << endl;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment