45template <
class _TypeT,
class _Allocator>
46list<_TypeT, _Allocator>::
51 _C_put_node (_C_node);
52 _RWSTD_NODE_LIST_FREE ();
57template <
class _TypeT,
class _Allocator>
58typename list<_TypeT, _Allocator>::iterator
59list<_TypeT, _Allocator>::erase (iterator __first, iterator __last)
64 while (!(__first == __last)) {
65 __first = erase (__first);
72#if !defined (_RWSTD_NO_LIST_NODE_BUFFER)
74template <
class _TypeT,
class _Allocator>
75void list<_TypeT, _Allocator>::_C_add_buffer (
bool __is_list_empty)
78 _RWSTD_SIZE_T __next_buffer_size = 1;
79 if(!__is_list_empty) {
80 if ((
void*)_C_buflist) {
88 _C_buf_pointer __tmp =
89 _C_buf_alloc_type (*this).allocate (1, (
void*)_C_buflist);
93 _C_node_alloc_type (*this).allocate (__next_buffer_size,
97 _C_buf_alloc_type (*this).deallocate (__tmp, 1);
101 __tmp->_C_next_buf = _C_buflist;
102 __tmp->_C_bufsize = __next_buffer_size;
105 _C_next_avail = _C_buflist->_C_buffer;
106 _C_last = _C_next_avail + __next_buffer_size;
110template <
class _TypeT,
class _Allocator>
111void list<_TypeT, _Allocator>::_C_free_buffers ()
113 while ((
void*)_C_buflist) {
114 _C_buf_pointer __tmp = _C_buflist;
115 _C_buflist = _C_buflist->_C_next_buf;
116 _C_node_alloc_type (*this).deallocate (__tmp->_C_buffer,
118 _C_buf_alloc_type (*this).deallocate (__tmp, 1);
128template <
class _TypeT,
class _Allocator>
129void list<_TypeT, _Allocator>::_C_transfer (iterator __it, iterator __first,
130 iterator __last, list& __x)
136 (*(_C_link_type ((*
_ITER_NODE (__last))._C_prev)))._C_next =
138 (*(_C_link_type ((*
_ITER_NODE (__first))._C_prev)))._C_next =
140 (*(_C_link_type ((*
_ITER_NODE (__it))._C_prev)))._C_next =
143 _C_link_type __tmp = _C_link_type ((*
_ITER_NODE (__it))._C_prev);
150 insert (__it, __first, __last);
151 __x.erase (__first, __last);
156template <
class _TypeT,
class _Allocator>
157void list<_TypeT, _Allocator>::resize (size_type __size, _TypeT __val)
159 if (__size >
size ())
160 insert (
end (), __size -
size (), __val);
161 else if (__size <
size ()) {
162 iterator __tmp = begin ();
163 advance (__tmp, __size);
164 erase (__tmp,
end ());
169template <
class _TypeT,
class _Allocator>
170list<_TypeT, _Allocator>&
171list<_TypeT, _Allocator>::operator= (
const list<_TypeT, _Allocator>& __rhs)
173 if (
this != &__rhs) {
174 iterator __first1 = begin ();
175 iterator __last1 =
end ();
176 const_iterator __first2 = __rhs.begin ();
177 const_iterator __last2 = __rhs.end ();
179 for ( ; !(__first1 == __last1) && !(__first2 == __last2);
180 ++__first1, ++__first2)
181 *__first1 = *__first2;
183 if (__first2 == __last2)
184 erase (__first1, __last1);
186 insert (__last1, __first2, __last2);
192template <
class _TypeT,
class _Allocator>
193void list<_TypeT, _Allocator>::splice (iterator __it, list &__x)
200#if !defined (_RWSTD_NO_LIST_NODE_BUFFER)
202 insert (__it, __x.begin (), __x.end ());
205 if (get_allocator () == __x.get_allocator ()) {
210 (*(_C_link_type ((*
_ITER_NODE (__it))._C_prev)))._C_next =
211 __x._C_node->_C_next;
213 __x._C_node->_C_next->_C_prev = (*
_ITER_NODE (__it))._C_prev;
214 (*
_ITER_NODE (__it))._C_prev = __x._C_node->_C_prev;
215 __x._C_node->_C_prev->_C_next =
_ITER_NODE (__it);
218 __x._C_node->_C_next =
219 __x._C_node->_C_prev = __x._C_node;
222 _C_length += __x._C_length;
227 insert (__it, __x.begin (), __x.end ());
234template <
class _TypeT,
class _Allocator>
235void list<_TypeT, _Allocator>::splice (iterator __i, list &__x, iterator __j)
240 if ( !(__x.end () == __j)
241 && !(__i == __j) && !(__i == ++iterator (__j))) {
243#if !defined (_RWSTD_NO_LIST_NODE_BUFFER)
248 if (get_allocator () == __x.get_allocator ()) {
253 (*(_C_link_type ((*
_ITER_NODE (__i))._C_prev)))._C_next =
257 _C_link_type __tmp = (*
_ITER_NODE (__i))._C_prev;
280template <
class _TypeT,
class _Allocator>
281void list<_TypeT, _Allocator>::
282splice (iterator __i, list &__x, iterator __j, iterator __k)
294#if !defined (_RWSTD_NO_LIST_NODE_BUFFER)
295 insert (__i, __j, __k);
296 __x.erase (__j, __k);
298 if (get_allocator () == __x.get_allocator ()) {
302 for (iterator __it = __j; __it != __k; ++__it) {
314 for (iterator __it = __j; __it != __k; ++__it) {
322 (*(_C_link_type ((*
_ITER_NODE (__k))._C_prev)))._C_next =
324 (*(_C_link_type ((*
_ITER_NODE (__j))._C_prev)))._C_next =
326 (*(_C_link_type ((*
_ITER_NODE (__i))._C_prev)))._C_next =
329 _C_link_type __tmp = _C_link_type ((*
_ITER_NODE (__i))._C_prev);
336 insert (__i, __j, __k);
337 __x.erase (__j, __k);
342template <
class _TypeT,
class _Allocator>
343void list<_TypeT, _Allocator>::remove (const_reference __val)
345 for (iterator __first = begin (), __last =
end (); !(__first == __last); ) {
346 iterator __next = __first;
348 if (*__first == __val)
355template <
class _TypeT,
class _Allocator>
356void list<_TypeT, _Allocator>::unique ()
358 iterator __first = begin ();
359 iterator __last =
end ();
361 if (__first == __last)
364 iterator __next = __first;
366 while (!(++__next == __last)) {
367 if (*__first == *__next)
376template <
class _TypeT,
class _Allocator>
377void list<_TypeT, _Allocator>::merge (list<_TypeT, _Allocator>& __x)
381 iterator __first1 = begin ();
382 iterator __last1 =
end ();
383 iterator __first2 = __x.begin ();
384 iterator __last2 = __x.end ();
386 while (!(__first1 == __last1) && !(__first2 == __last2)) {
387 if (*__first2 < *__first1) {
388 iterator __next = __first2;
389 _C_transfer (__first1, __first2, ++__next, __x);
396 if (!(__first2 == __last2))
397 _C_transfer (__last1, __first2, __last2, __x);
401template <
class _TypeT,
class _Allocator>
402void list<_TypeT, _Allocator>::reverse ()
407 for (iterator __first = ++begin (); !(__first ==
end ()); ) {
408 iterator __tmp = __first;
409 _C_transfer (begin (), __tmp, ++__first, *
this);
415template <
class _TypeT,
class _Allocator>
416void list<_TypeT, _Allocator>::sort ()
418 for (size_type __n = 1; __n <
size (); __n *= 2) {
419 iterator __i1 = begin (),
423 _C_advance (__i2, (difference_type)__n,
end ());
424 _C_advance (__i3, (difference_type)(2 * __n),
end ());
426 for (size_type __m = 0;
427 __m < (
size () + (2 * __n)) / (__n * 2); __m++) {
429 if (!(__i1 ==
end ()) && !(__i2 ==
end ())) {
430 _C_adjacent_merge (__i1, __i2, __i3);
432 _C_advance (__i2, (difference_type) __n,
end ());
433 _C_advance (__i3, (difference_type) 2 * __n,
end ());
440template <
class _TypeT,
class _Allocator>
441void list<_TypeT, _Allocator>::
442_C_adjacent_merge (iterator __first1, iterator __last1, iterator __last2)
444 difference_type __n =
_DISTANCE (__first1, __last1, difference_type);
446 for (iterator __first2 = __last1; __n >= 0 && !(__first2 == __last2); ) {
447 if (*__first2 < *__first1) {
448 iterator __next = __first2;
449 _C_transfer (__first1, __first2, ++__next, *
this);
460template <
class _TypeT,
class _Allocator>
461template<
class _Compare>
462void list<_TypeT, _Allocator>::
463_C_adjacent_merge (iterator __first1, iterator __last1, iterator __last2,
466 difference_type __n =
_DISTANCE (__first1, __last1, difference_type);
468 for (iterator __first2 = __last1; __n >= 0 && !(__first2 == __last2); ) {
469 if (__cmp (*__first2, *__first1)) {
470 iterator __next = __first2;
471 _C_transfer (__first1, __first2, ++__next, *
this);
482template<
class _TypeT,
class _Allocator>
483template<
class _Predicate>
484void list<_TypeT, _Allocator>::remove_if (_Predicate __pred)
486 iterator __first = begin ();
487 iterator __last =
end ();
489 while (!(__first == __last)) {
490 iterator __next = __first;
492 if (__pred (*__first))
499template<
class _TypeT,
class _Allocator>
500template<
class _BinaryPredicate>
501void list<_TypeT, _Allocator>::unique (_BinaryPredicate __pred)
503 iterator __first = begin ();
504 iterator __last =
end ();
506 if (__first == __last)
509 iterator __next = __first;
510 while (!(++__next == __last)) {
511 if (__pred (*__first, *__next))
520template<
class _TypeT,
class _Allocator>
521template<
class _Compare>
522void list<_TypeT, _Allocator>::
523merge (list<_TypeT, _Allocator>& __x, _Compare __cmp)
527 iterator __first1 = begin ();
528 iterator __last1 =
end ();
529 iterator __first2 = __x.begin ();
530 iterator __last2 = __x.end ();
532 while (!(__first1 == __last1) && !(__first2 == __last2)) {
533 if (__cmp (*__first2, *__first1)) {
534 iterator __next = __first2;
535 _C_transfer (__first1, __first2, ++__next, __x);
542 if (!(__first2 == __last2))
543 _C_transfer (__last1, __first2, __last2, __x);
547template <
class _TypeT,
class _Allocator>
548template<
class _Compare>
549void list<_TypeT, _Allocator>::sort (_Compare __cmp)
551 for (size_type __n = 1; __n <
size (); __n *= 2) {
553 iterator __it1 = begin (),
557 _C_advance (__it2, __n,
end ());
558 _C_advance (__it3, 2 * __n,
end ());
560 for (size_type __m = 0;
561 __m != (
size () + (2 * __n)) / (__n * 2); ++__m) {
563 if (!(__it1 ==
end ()) && !(__it2 ==
end ())) {
564 _C_adjacent_merge (__it1, __it2, __it3, __cmp);
567 _C_advance (__it2, __n,
end ());
568 _C_advance (__it3, 2 * __n,
end ());
#define _RWSTD_NAMESPACE(name)
#define _RWSTD_NEW_CAPACITY(ignore, what, from)
#define _RWSTD_ASSERT(ignore)
#define _DISTANCE(first, last, ignore)
#define _RWSTD_ASSERT_RANGE(ign1, ign2)