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 print>
- ostream& Print(ostream& out, const print& container){
- bool isfirst=1;
- for (const auto& element : container) {
- if (isfirst) out << ""s;
- else out << ", "s;
- isfirst=0;
- out << element << ""s;
- }
- return out;
- }
- template <typename invect>
- ostream& operator<<(ostream& out, const vector<invect>& container) {
- out<<"[";
- Print(out, container);
- out<<"]";
- return out;
- }
- template <typename inset>
- ostream& operator<<(ostream& out, const set<inset>& container) {
- out<<"{";
- Print(out, container);
- out<<"}";
- return out;
- }
- template <typename Key, typename Value>
- ostream& operator<<(ostream& out, const map<Key, Value>& container) {
- out<<"<";
- bool isfirst=1;
- for (const auto& [key, value] : container){
- if (isfirst) out << ""s;
- else out << ", "s;
- isfirst=0;
- out<<"("<<key<<", "<<value<<")";
- }
- 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
Advertisement