-
Notifications
You must be signed in to change notification settings - Fork 0
/
typename_test1.cpp
67 lines (58 loc) · 1.04 KB
/
typename_test1.cpp
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
61
62
63
64
65
66
67
#include <inttypes.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;
void print(uint32_t i)
{
cout << i << endl;
}
template <class T>
class Test
{
public:
Test(T* t) : m_t(t){}
void func()
{
typename T::iterator it = m_t->begin();
typename T::iterator it_end = m_t->end();
for_each(it, it_end, print);
}
private:
T* m_t;
};
void print2(uint32_t i)
{
cout << i + 2 << endl;
}
template <>
class Test<list<uint32_t> >
{
public:
Test(list<uint32_t>* t) : m_t(t){}
void func()
{
list<uint32_t>::iterator it = m_t->begin();
list<uint32_t>::iterator it_end = m_t->end();
for_each(it, it_end, print2);
}
private:
list<uint32_t>* m_t;
};
int main()
{
vector<uint32_t> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
Test<vector<uint32_t> > test(&v);
test.func();
list<uint32_t> list1;
list1.push_back(1);
list1.push_back(2);
list1.push_back(3);
Test<list<uint32_t> > test2(&list1);
test2.func();
return 0;
}