This is comment for paste
Задача 6
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <map>
- using namespace std;
- template<typename key, typename value>
- void Print(ostream& out, const map<key, value>& container){
- bool first = true;
- for(const auto& [name, age]: container){
- if(!first){
- cout << ", ";
- }
- first = false;
- out << "(" << name << ", " << age << ")";
- }
- }
- template <typename T>
- void Print(ostream& out, const T& container ){
- bool first = true;
- for (const auto& element : container) {
- if(!first){
- out << ", ";
- }
- first = false;
- out << element;
- }
- }
- template <typename T>
- ostream& operator<<(ostream& out, const vector<T>& container) {
- out << "[";
- Print(out, container);
- out << "]";
- return out;
- }
- template <typename T>
- ostream& operator<<(ostream& out, const set<T>& container) {
- out << "{";
- Print(out, container);
- out << "}";
- return out;
- }
- template <typename key, typename value>
- ostream& operator<<(ostream& out, const map<key, value>& container) {
- out << "<";
- Print(out, container);
- out << ">";
- return out;
- }
- int main() {
- 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;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment