16 D_list_item() : _dli_next(0) {}
18 friend class D_list_item_policy;
20 D_list_item(D_list_item
const &);
21 void operator = (D_list_item
const &);
23 D_list_item *_dli_next, *_dli_prev;
26class D_list_item_policy
29 typedef D_list_item Item;
30 static D_list_item *&prev(D_list_item *e) {
return e->_dli_prev; }
31 static D_list_item *&next(D_list_item *e) {
return e->_dli_next; }
32 static D_list_item *prev(D_list_item
const *e) {
return e->_dli_prev; }
33 static D_list_item *next(D_list_item
const *e) {
return e->_dli_next; }
37struct Sd_list_head_policy
40 static T *head(Head_type h) {
return h; }
41 static void set_head(Head_type &h, T *v) { h = v; }
46 typename C = D_list_item_policy
51 template<
typename VALUE,
typename ITEM >
55 typedef VALUE *Value_type;
56 typedef VALUE *value_type;
60 bool operator == (__Iterator
const &o)
const
61 {
return _c == o._c; }
63 bool operator != (__Iterator
const &o)
const
64 {
return _c != o._c; }
66 __Iterator &operator ++ ()
72 __Iterator &operator -- ()
78 Value_type operator * ()
const {
return static_cast<Value_type
>(_c); }
79 Value_type operator -> ()
const {
return static_cast<Value_type
>(_c); }
82 friend class D_list_cyclic;
84 explicit __Iterator(ITEM *s) : _c(s) {}
90 typedef T *Value_type;
91 typedef T *value_type;
92 typedef __Iterator<T, typename C::Item> Iterator;
93 typedef Iterator Const_iterator;
95 static void remove(T *e)
97 C::next(C::prev(e)) = C::next(e);
98 C::prev(C::next(e)) = C::prev(e);
102 static Iterator erase(Iterator
const &e)
104 typename C::Item *n = C::next(*e);
109 static Iterator iter(T
const *e) {
return Iterator(
const_cast<T*
>(e)); }
111 static bool in_list(T
const *e) {
return C::next(
const_cast<T*
>(e)); }
112 static bool has_sibling(T
const *e) {
return C::next(
const_cast<T*
>(e)) != e; }
114 static Iterator insert_after(T *e, Iterator
const &pos)
117 C::next(e) = C::next(*pos);
118 C::prev(C::next(*pos)) = e;
123 static Iterator insert_before(T *e, Iterator
const &pos)
126 C::prev(e) = C::prev(*pos);
127 C::next(C::prev(*pos)) = e;
132 static T *self_insert(T *e)
133 { C::next(e) = C::prev(e) = e;
return e; }
135 static void remove_last(T *e)
139 static Iterator __iter(
typename C::Item *e) {
return Iterator(e); }
144 typename C = D_list_item_policy,
145 typename H = Sd_list_head_policy<T>,
148class Sd_list :
public D_list_cyclic<T, C>
151 typedef D_list_cyclic<T, C> Base;
154 typedef typename Base::Iterator Iterator;
158 Sd_list() {
if (!BSS) H::set_head(_f, 0); }
160 bool empty()
const {
return !H::head(_f); }
161 T *front()
const {
return H::head(_f); }
168 Base::remove_last(e);
173 if (e == H::head(_f))
174 H::set_head(_f,
static_cast<T*
>(C::next(h)));
179 Iterator erase(Iterator
const &e)
181 typename C::Item *n = C::next(*e);
186 void push(T *e, Pos pos)
190 H::set_head(_f, Base::self_insert(e));
193 Base::insert_before(e, this->iter(h));
199 void push_back(T *e) { push(e, Back); }
200 void push_front(T *e) { push(e, Front); }
201 void rotate_to(T *h) { H::set_head(_f, h); }
203 typename H::Head_type
const &head()
const {
return _f; }
204 typename H::Head_type &head() {
return _f; }
207 Sd_list(Sd_list
const &);
208 void operator = (Sd_list
const &);
210 typename H::Head_type _f;
215 typename C = D_list_item_policy,
218class D_list :
public D_list_cyclic<T, C>
221 typedef D_list_cyclic<T, C> Base;
222 typedef typename C::Item Internal_type;
228 typedef typename Base::Iterator Iterator;
229 typedef typename Base::Const_iterator Const_iterator;
230 typedef T* value_type;
231 typedef T* Value_type;
233 D_list() { this->self_insert(
static_cast<T*
>(&_h)); }
235 bool empty()
const {
return C::next(
static_cast<T
const *
>(&_h)) == &_h; }
237 static void remove(T *e) { Base::remove(e); }
238 Iterator erase(Iterator
const &e) {
return Base::erase(e); }
240 void push(T *e, Pos pos)
243 Base::insert_after(e, end());
245 Base::insert_before(e, end());
248 void push_back(T *e) { push(e, Back); }
249 void push_front(T *e) { push(e, Front); }
251 Iterator begin()
const {
return this->__iter(C::next(
const_cast<Internal_type *
>(&_h))); }
252 Iterator end()
const {
return this->__iter(
const_cast<Internal_type *
>(&_h)); }
255 D_list(D_list
const &);
256 void operator = (D_list
const &);