Advertisement
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>& kunteynir){
- bool first_ap = true;
- for(const auto& [name, age]: kunteynir){
- if(!first_ap){
- cout << ", ";
- }
- first_ap = false;
- out << "(" << name << ", " << age << ")";
- }
- }
- /*
- ИЛИ
- template<typename key, typename value>
- ostream& operator<<(ostream& out, const pair<key, value>& kunteynir){
- return out << "(" << kunteynir.first << ", " << kunteynir.second << ")";
- }
- */
- template<typename type>
- void Print(ostream& out, const type& kunteynir){
- bool first_ap = true;
- for(const auto& kun: kunteynir){
- if(!first_ap){
- out << ", ";
- }
- first_ap = false;
- out << kun;
- }
- }
- template<typename type>
- ostream& operator<< (ostream& out, const set<type>kunteynir){
- out << "{";
- Print(out, kunteynir);
- out << "}";
- return out;
- }
- template<typename type>
- ostream& operator<< (ostream& out, const vector<type>kunteynir){
- out << "[";
- Print(out, kunteynir);
- out << "]";
- return out;
- }
- template<typename key, typename value>
- ostream& operator<< (ostream& out, const map<key, value>kunteynir){
- out << "<";
- Print(out, kunteynir);
- out << ">";
- return out;
- }
- int main() {
- const vector<int> ages{10, 5, 2, 12};
- const set<string> set_ages{"Белка", "Георгий", "Мурка", "Рюрик"};
- const map<string, int> cat_ages = {
- {"Мурка"s, 10},
- {"Белка"s, 5},
- {"Георгий"s, 2},
- {"Рюрик"s, 12}
- };
- cout << ages << endl;
- cout << set_ages << endl;
- cout << cat_ages << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement