blob: 1bc1ce3591e172bcd6c239a5349aa698ea01d300 (
plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
// { dg-do assemble }
// GROUPS passed scope pt
class Link {
public:
Link();
Link(Link *);
private:
Link *next_;
friend class IListBase;
friend class IListIterBase;
};
inline
Link::Link() : next_(0)
{
}
inline
Link::Link(Link *next) : next_(next)
{
}
class IListBase {
public:
IListBase();
IListBase(Link *);
void append(Link *);
void insert(Link *);
Link *head();
int empty();
Link *get();
void remove(Link *);
private:
Link *head_;
friend class IListIterBase;
};
inline
IListBase::IListBase() : head_(0)
{
}
inline
IListBase::IListBase(Link *head) : head_(head)
{
}
inline
void IListBase::insert(Link *p)
{
p->next_ = head_;
head_ = p;
}
inline
Link *IListBase::head()
{
return head_;
}
inline
int IListBase::empty()
{
return head_ == 0;
}
inline
Link *IListBase::get()
{
Link *tem = head_;
head_ = head_->next_;
return tem;
}
template<class T> class IListIter;
template<class T>
class IList : private IListBase {
public:
IList() { }
IList(T *p) : IListBase(p) { }
~IList();
void append(T *p) { IListBase::append(p); }
void insert(T *p) { IListBase::insert(p); }
void remove(T *p) { IListBase::remove(p); }
T *head() { return (T *)IListBase::head(); }
T *get() { return (T *)IListBase::get(); }
IListBase::empty;
friend class IListIter<T>;
};
template<class T>
IList<T>::~IList()
{
while (!empty())
delete get();
}
class IListIterBase {
public:
IListIterBase(const IListBase &);
int done();
Link *cur();
void next();
private:
Link *p_;
};
inline
IListIterBase::IListIterBase(const IListBase &list) : p_(list.head_)
{
}
inline
int IListIterBase::done()
{
return p_ == 0;
}
inline
Link *IListIterBase::cur()
{
return p_;
}
inline
void IListIterBase::next()
{
p_ = p_->next_;
}
template<class T>
class IListIter : private IListIterBase {
public:
IListIter(const IList<T> &list) : IListIterBase(list) { }
T *cur() { return (T *)IListIterBase::cur(); }
IListIterBase::next;
IListIterBase::done;
};
struct A {
IList<Link> list;
int x;
void foo();
};
void A::foo()
{
for (IListIter<Link> iter(list); !iter.done(); iter.next())
;
x = 0;
}
|