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>
- ostream& Print (ostream& out, const map<Key, Value>& container) {
- /*for(const auto& Key: container){
- Print(out, Key);
- }*/
- bool checker = true;
- for (const auto& [key, value] : container) {
- if(checker==false){
- out<<", ";
- }
- checker=false;
- out << "("s<<key<<", "s<<value<<")"s;
- }
- return out;
- }
- template <typename Container>
- ostream& Print (ostream& out, const Container& container){
- /*int counter = 1, last_index = container.size();
- for (const auto& element : container) {
- if(counter == last_index){
- out << element;
- }else{
- out << element<< ", "s;
- }
- ++counter;
- }
- return out;*/
- bool checker = true;
- for (const auto& element : container) {
- if (checker==false) {
- out << ", "s;
- }
- checker = false;
- out << element;
- }
- return out;
- }
- template <typename Key, typename Value>
- ostream& operator<<(ostream& out, const map<Key, Value>& container) {
- return out<<"<"s, Print(out, container), out<<">"s;
- }
- template <typename Container>
- ostream& operator<<(ostream& out, const vector<Container>& container) {
- return out<<"["s, Print(out, container), out<<"]"s;
- }
- template <typename Container>
- ostream& operator<<(ostream& out, const set<Container>& container) {
- return out<<"{"s, Print(out, container), out<<"}"s;
- }
- /*int main() {
- const vector<string> cats = {"Мурка"s, "Белка"s, "Георгий"s, "Рюрик"s};
- cout << cats << endl;
- }*/
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment