3 * Copyright (c) 1996,1997
4 * Silicon Graphics Computer Systems, Inc.
9 * This material is provided "as is", with absolutely no warranty expressed
10 * or implied. Any use is at your own risk.
12 * Permission to use or copy this software for any purpose is hereby granted
13 * without fee, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
22 #ifndef _STLP_INTERNAL_SLIST_H
23 # include <stl/_slist.h>
27 # define slist __WORKAROUND_DBG_RENAME(slist)
28 # if defined (_STLP_NESTED_TYPE_PARAM_BUG)
29 # define size_type size_t
34 template <class _Tp, class _Alloc>
36 _Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first,
37 _Slist_node_base* __last_node) {
38 _Slist_node<_Tp>* __cur = (_Slist_node<_Tp>*) (__before_first->_M_next);
39 while (__cur != __last_node) {
40 _Slist_node<_Tp>* __tmp = __cur;
41 __cur = (_Slist_node<_Tp>*) __cur->_M_next;
42 _STLP_STD::_Destroy(&__tmp->_M_data);
43 _M_head.deallocate(__tmp,1);
45 __before_first->_M_next = __last_node;
49 template <class _Tp, class _Alloc>
50 slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x)
53 _Node_base* __p1 = &this->_M_head._M_data;
54 _Node* __n1 = (_Node*) this->_M_head._M_data._M_next;
55 const _Node* __n2 = (const _Node*) __x._M_head._M_data._M_next;
56 while (__n1 && __n2) {
57 __n1->_M_data = __n2->_M_data;
59 __n1 = (_Node*) __n1->_M_next;
60 __n2 = (const _Node*) __n2->_M_next;
63 this->_M_erase_after(__p1, 0);
65 _M_insert_after_range(__p1, const_iterator((_Node*)__n2),
71 template <class _Tp, class _Alloc>
72 void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
73 _Node_base* __prev = &this->_M_head._M_data;
74 _Node* __node = (_Node*) this->_M_head._M_data._M_next;
75 for ( ; __node != 0 && __n > 0 ; --__n) {
76 __node->_M_data = __val;
78 __node = (_Node*) __node->_M_next;
81 _M_insert_after_fill(__prev, __n, __val);
83 this->_M_erase_after(__prev, 0);
87 template <class _Tp, class _Alloc>
88 void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x)
90 _Node_base* __cur = &this->_M_head._M_data;
91 while (__cur->_M_next != 0 && __len > 0) {
93 __cur = __cur->_M_next;
96 this->_M_erase_after(__cur, 0);
98 _M_insert_after_fill(__cur, __len, __x);
101 template <class _Tp, class _Alloc>
102 void slist<_Tp,_Alloc>::remove(const _Tp& __val)
104 _Node_base* __cur = &this->_M_head._M_data;
105 while (__cur && __cur->_M_next) {
106 if (((_Node*) __cur->_M_next)->_M_data == __val)
107 this->_M_erase_after(__cur);
109 __cur = __cur->_M_next;
113 template <class _Tp, class _Alloc>
114 void slist<_Tp,_Alloc>::unique()
116 _Node_base* __cur = this->_M_head._M_data._M_next;
118 while (__cur->_M_next) {
119 if (((_Node*)__cur)->_M_data ==
120 ((_Node*)(__cur->_M_next))->_M_data)
121 this->_M_erase_after(__cur);
123 __cur = __cur->_M_next;
128 template <class _Tp, class _Alloc>
129 void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x)
131 _Node_base* __n1 = &this->_M_head._M_data;
132 while (__n1->_M_next && __x._M_head._M_data._M_next) {
133 if (((_Node*) __x._M_head._M_data._M_next)->_M_data <
134 ((_Node*) __n1->_M_next)->_M_data)
135 _Sl_global_inst::__splice_after(__n1, &__x._M_head._M_data, __x._M_head._M_data._M_next);
136 __n1 = __n1->_M_next;
138 if (__x._M_head._M_data._M_next) {
139 __n1->_M_next = __x._M_head._M_data._M_next;
140 __x._M_head._M_data._M_next = 0;
144 template <class _Tp, class _Alloc>
145 void slist<_Tp,_Alloc>::sort()
147 if (this->_M_head._M_data._M_next && this->_M_head._M_data._M_next->_M_next) {
152 _Sl_global_inst::__splice_after(&__carry._M_head._M_data, &this->_M_head._M_data, this->_M_head._M_data._M_next);
154 while (__i < __fill && !__counter[__i].empty()) {
155 __counter[__i].merge(__carry);
156 __carry.swap(__counter[__i]);
159 __carry.swap(__counter[__i]);
164 for (int __i = 1; __i < __fill; ++__i)
165 __counter[__i].merge(__counter[__i-1]);
166 this->swap(__counter[__fill-1]);
175 #endif /* _STLP_SLIST_C */