View difference between Paste ID: 2mPJvTwg and NC1WCQXq
SHOW: | | - or go back to the newest paste.
1
#include <iostream>
2
#include <map>
3
#include <set>
4
#include <vector>
5
6
using namespace std;
7
8
template <typename First, typename Second>
9
ostream& operator<<(ostream& out, const pair<First, Second>& p) {
10
    return out << '(' << p.first << ", "s << p.second << ')';
11
}
12
13
template <typename Container>
14
void Print(ostream& out, const Container& container) {
15
    bool is_first = true;
16
    for (const auto& element : container) {
17
        if (!is_first) {
18
            out << ", "s;
19
        }
20
        is_first = false;
21
        out << element;
22
    }
23
}
24
25
template <typename Element>
26
ostream& operator<<(ostream& out, const vector<Element>& container) {
27
    out << '[';
28
    Print(out, container);
29
    out << ']';
30
    return out;
31
}
32
33
template <typename Element>
34
ostream& operator<<(ostream& out, const set<Element>& container) {
35
    out << '{';
36
    Print(out, container);
37
    out << '}';
38
    return out;
39
}
40
41
template <typename Key, typename Value>
42
ostream& operator<<(ostream& out, const map<Key, Value>& container) {
43
    out << '<';
44
    Print(out, container);
45
    out << '>';
46
    return out;
47
}
48
49
int main() {
50
    const set<string> cats = {"Мурка"s, "Белка"s, "Георгий"s, "Рюрик"s};
51
    cout << cats << endl;
52
53
    const vector<int> ages = {10, 5, 2, 12};
54
    cout << ages << endl;
55
56
    const map<string, int> cat_ages = {
57
        {"Мурка"s, 10},
58
        {"Белка"s, 5},
59
        {"Георгий"s, 2},
60
        {"Рюрик"s, 12}
61
    };
62
    cout << cat_ages << endl;
63
}