This is comment for paste
Задача 6
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename Element, typename T>
- void Print(ostream &out, const map<Element, T> &container){
- int count = 1;
- for(const auto &[element,age] : container){
- out << "("s << element << ", " << age << ")";
- if(container.size() > count){
- out << ", "s;
- ++count;
- }
- }
- }
- template <typename Element>
- void Print(ostream &out, const Element &container){
- bool is_map = true;
- for(const auto &element : container){
- if(!is_map)
- out << ", "s;
- is_map = false;
- out << element;
- }
- }
- template <typename Element>
- ostream &operator<<(ostream &out, const vector<Element> &container){
- out << "["s;
- Print(out, container);
- out << "]"s;
- return out;
- }
- template <typename Element>
- ostream &operator<<(ostream &out, const set<Element> &container){
- out << "{"s;
- Print(out, container);
- out << "}"s;
- return out;
- }
- template <typename Element, typename T>
- ostream &operator<<(ostream &out, const map<Element,T> &container){
- out << "<"s;
- Print(out, container);
- out << ">"s;
- return out;
- }
- int main(){
- setlocale(LC_ALL, "");
- const set<string> cats = {"Мурка"s, "Белка"s, "Георгий"s, "Рюрик"s};
- cout << cats << endl;
- const vector<int> ages = {10, 5, 2, 12};
- cout << ages << endl;
- const map<string, int> cat_ages = {
- {"Мурка"s, 10},
- {"Белка"s, 5},
- {"Георгий"s, 2},
- {"Рюрик"s, 12}
- };
- cout << cat_ages << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment