-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_container.cpp
More file actions
40 lines (35 loc) · 801 Bytes
/
Copy pathprint_container.cpp
File metadata and controls
40 lines (35 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <set>
struct X
{
int a = 0;
std::string text;
};
std::ostream& operator<<(std::ostream& os, X const& arg)
{
os << "a = " << arg.a << ", text = " << arg.text;
return os;
}
template <typename T>
void print(T container)
{
using item = typename std::decay_t<decltype(*begin(container))>;
std::copy(begin(container), end(container), std::ostream_iterator<item>(std::cout, " "));
std::cout << '\n';
}
int main()
{
std::vector<int> v1 {1, 2, 3, 4};
std::vector<std::string> v2 { "123", "2", "3", "4"};
std::set<int> s1{ 5, 10, 20};
std::vector<X> v3{{1, "test"}, {2, "zero"}};
print(v1);
print(v2);
print(s1);
print(v3);
return 0;
}