-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrebind.cpp
52 lines (37 loc) · 954 Bytes
/
rebind.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
/*
* HOME : ecourse.co.kr
* EMAIL : smkang @ codenuri.co.kr
* COURSENAME : C++ Template Programming
* MODULE : rebind.cpp
* Copyright (C) 2017 CODENURI Inc. All rights reserved.
*/
// 실제 allocator 소스는 user_define_allocator.cpp 소스를 참고 하세요.
template<typename T> class allocator
{
public:
T* allocate(int sz) { return new T[sz]; }
void deallocate(T* p) { delete[] p; }
//
template<typename U> struct rebind
{
typedef allocator<U> other;
};
};
// rebind
template<typename T, typename Ax = allocator<T> > class list
{
struct NODE { T data; NODE *next, *prev; };
//Ax ax; // allocator<int>
//allocator<int>::rebind<NODE>::other ax; // allocator<NODE> ax;
typename Ax::template rebind<NODE>::other ax; // allocator<NODE> ax;
public:
void push_front(const T& a)
{
ax.allocate(1);
}
};
int main()
{
list<int> s;
s.push_front(10);
}