-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_container.cc
More file actions
60 lines (50 loc) · 1.32 KB
/
Copy pathprint_container.cc
File metadata and controls
60 lines (50 loc) · 1.32 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <numeric>
#include <algorithm>
#include <iterator>
#include <vector>
#include <set>
#include <iostream>
/* Template function for vector, set, list */
template <typename T>
void print(T& input) {
typedef typename std::iterator_traits<typename T::iterator>::value_type Type;
std::copy(input.begin(), input.end(), std::ostream_iterator<Type>(std::cout, " "));
std::cout << "\n";
}
/* function for arrays */
template<typename T, int size>
void print(T(&input) [size] ) {
std::cout <<"Reference: ";
std::copy(input, input+size, std::ostream_iterator<T>(std::cout, " "));
std::cout << "\n";
}
template<typename T>
void print(T* input, int size) {
std::cout <<"Pointer: ";
std::copy(input, input+size, std::ostream_iterator<T>(std::cout, " "));
std::cout << "\n";
}
struct unique_number {
private:
int number;
public:
unique_number()
: number(0) {
}
int operator()() {
return ++number;
}
};
int main() {
using namespace std;
std::vector<int> V(10);
std::generate_n(V.begin(), 10, unique_number());
std::set<int> S(V.begin(), V.end());
int array_int[] = { 1,2,3,4,5,6,7 };
char array_char[] = { '1', '2', '3', '4' };
print(V);
print(S);
print(array_int, sizeof(array_int)/sizeof(array_int[0]));
print(array_char);
return 0;
}