]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c++/stl/stl/_list.h
Add STLport 5.1.4
[polintos/scott/priv.git] / include / c++ / stl / stl / _list.h
1 /*
2  *
3  * Copyright (c) 1994
4  * Hewlett-Packard Company
5  *
6  * Copyright (c) 1996,1997
7  * Silicon Graphics Computer Systems, Inc.
8  *
9  * Copyright (c) 1997
10  * Moscow Center for SPARC Technology
11  *
12  * Copyright (c) 1999
13  * Boris Fomitchev
14  *
15  * This material is provided "as is", with absolutely no warranty expressed
16  * or implied. Any use is at your own risk.
17  *
18  * Permission to use or copy this software for any purpose is hereby granted
19  * without fee, provided the above notices are retained on all copies.
20  * Permission to modify the code and to distribute modified code is granted,
21  * provided the above notices are retained, and a notice that the code was
22  * modified is included with the above copyright notice.
23  *
24  */
25
26 /* NOTE: This is an internal header file, included by other STL headers.
27  *   You should not attempt to use it directly.
28  */
29
30 #ifndef _STLP_INTERNAL_LIST_IMPL_H
31 #define _STLP_INTERNAL_LIST_IMPL_H
32
33 #ifndef _STLP_INTERNAL_ALGOBASE_H
34 #  include <stl/_algobase.h>
35 #endif
36
37 #ifndef _STLP_INTERNAL_ALLOC_H
38 #  include <stl/_alloc.h>
39 #endif
40
41 #ifndef _STLP_INTERNAL_ITERATOR_H
42 #  include <stl/_iterator.h>
43 #endif
44
45 #ifndef _STLP_INTERNAL_CONSTRUCT_H
46 #  include <stl/_construct.h>
47 #endif
48
49 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
50 #  include <stl/_function_base.h>
51 #endif
52
53 _STLP_BEGIN_NAMESPACE
54
55 _STLP_MOVE_TO_PRIV_NAMESPACE
56
57 struct _List_node_base {
58   _List_node_base* _M_next;
59   _List_node_base* _M_prev;
60 };
61
62 template <class _Dummy>
63 class _List_global {
64 public:
65   typedef _List_node_base _Node_base;
66   static void  _STLP_CALL _Transfer(_Node_base* __pos,
67                                     _Node_base* __first, _Node_base* __last);
68 };
69
70 #if defined (_STLP_USE_TEMPLATE_EXPORT)
71 _STLP_EXPORT_TEMPLATE_CLASS _List_global<bool>;
72 #endif
73 typedef _List_global<bool> _List_global_inst;
74
75 template <class _Tp>
76 class _List_node : public _List_node_base {
77 public:
78   _Tp _M_data;
79   __TRIVIAL_STUFF(_List_node)
80 };
81
82 struct _List_iterator_base {
83   typedef size_t                     size_type;
84   typedef ptrdiff_t                  difference_type;
85   typedef bidirectional_iterator_tag iterator_category;
86
87   _List_node_base* _M_node;
88
89   _List_iterator_base(_List_node_base* __x) : _M_node(__x) {}
90
91   void _M_incr() { _M_node = _M_node->_M_next; }
92   void _M_decr() { _M_node = _M_node->_M_prev; }
93 };
94
95
96 template<class _Tp, class _Traits>
97 struct _List_iterator : public _List_iterator_base {
98   typedef _Tp value_type;
99   typedef typename _Traits::pointer    pointer;
100   typedef typename _Traits::reference  reference;
101
102   typedef _List_iterator<_Tp, _Traits>         _Self;
103   typedef typename _Traits::_NonConstTraits    _NonConstTraits;
104   typedef _List_iterator<_Tp, _NonConstTraits> iterator;
105   typedef typename _Traits::_ConstTraits       _ConstTraits;
106   typedef _List_iterator<_Tp, _ConstTraits>    const_iterator;
107
108   typedef bidirectional_iterator_tag iterator_category;
109   typedef _List_node<_Tp> _Node;
110   typedef size_t size_type;
111   typedef ptrdiff_t difference_type;
112
113   explicit _List_iterator(_List_node_base* __x) : _List_iterator_base(__x) {}
114   _List_iterator() : _List_iterator_base(0) {}
115   //copy constructor for iterator and constructor from iterator for const_iterator
116   _List_iterator(const iterator& __x) :  _List_iterator_base(__x._M_node) {}
117
118   reference operator*() const { return __STATIC_CAST(_Node*, this->_M_node)->_M_data; }
119
120   _STLP_DEFINE_ARROW_OPERATOR
121
122   _Self& operator++() {
123     this->_M_incr();
124     return *this;
125   }
126   _Self operator++(int) {
127     _Self __tmp = *this;
128     this->_M_incr();
129     return __tmp;
130   }
131   _Self& operator--() {
132     this->_M_decr();
133     return *this;
134   }
135   _Self operator--(int) {
136     _Self __tmp = *this;
137     this->_M_decr();
138     return __tmp;
139   }
140   bool operator==(const_iterator __y ) const {
141     return this->_M_node == __y._M_node;
142   }
143   bool operator!=(const_iterator __y ) const {
144     return this->_M_node != __y._M_node;
145   }
146 };
147
148 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
149 _STLP_MOVE_TO_STD_NAMESPACE
150 template <class _Tp, class _Traits>
151 struct __type_traits<_STLP_PRIV _List_iterator<_Tp, _Traits> > {
152   typedef __false_type   has_trivial_default_constructor;
153   typedef __true_type    has_trivial_copy_constructor;
154   typedef __true_type    has_trivial_assignment_operator;
155   typedef __true_type    has_trivial_destructor;
156   typedef __false_type   is_POD_type;
157 };
158 _STLP_MOVE_TO_PRIV_NAMESPACE
159 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
160
161 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
162 _STLP_MOVE_TO_STD_NAMESPACE
163 template <class _Tp, class _Traits>
164 inline _Tp* value_type(const _STLP_PRIV _List_iterator<_Tp, _Traits>&) { return 0; }
165 inline bidirectional_iterator_tag iterator_category(const _STLP_PRIV _List_iterator_base&) { return bidirectional_iterator_tag();}
166 inline ptrdiff_t* distance_type(const _STLP_PRIV _List_iterator_base&) { return 0; }
167 _STLP_MOVE_TO_PRIV_NAMESPACE
168 #endif
169
170 // Base class that encapsulates details of allocators and helps
171 // to simplify EH
172
173 template <class _Tp, class _Alloc>
174 class _List_base {
175 protected:
176   _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
177   typedef _List_node_base _Node_base;
178   typedef _List_node<_Tp> _Node;
179   typedef _List_base<_Tp, _Alloc> _Self;
180   typedef typename _Alloc_traits<_Node, _Alloc>::allocator_type _Node_allocator_type;
181 public:
182   typedef _STLP_alloc_proxy<_Node_base, _Node, _Node_allocator_type> _AllocProxy;
183   typedef typename _Alloc_traits<_Tp, _Alloc>::allocator_type allocator_type;
184
185   allocator_type get_allocator() const
186   { return _STLP_CONVERT_ALLOCATOR((const _Node_allocator_type&)_M_node, _Tp); }
187
188   _List_base(const allocator_type& __a) : _M_node(_STLP_CONVERT_ALLOCATOR(__a, _Node), _Node_base())
189   { _M_empty_initialize(); }
190   _List_base(__move_source<_Self> src) :
191     _M_node(__move_source<_AllocProxy>(src.get()._M_node)) {
192     if (src.get().empty())
193       //We force this to empty.
194       _M_empty_initialize();
195     else {
196       src.get()._M_empty_initialize();
197       _M_node._M_data._M_prev->_M_next = _M_node._M_data._M_next->_M_prev = &_M_node._M_data;
198     }
199   }
200
201   ~_List_base()
202   { clear(); }
203
204   void clear();
205   bool empty() const { return _M_node._M_data._M_next == &_M_node._M_data; }
206
207   void _M_empty_initialize() {
208     _M_node._M_data._M_next = &_M_node._M_data;
209     _M_node._M_data._M_prev = _M_node._M_data._M_next;
210   }
211
212 public:
213   _AllocProxy _M_node;
214 };
215
216 #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
217 #  define list _STLP_PTR_IMPL_NAME(list)
218 #elif defined (_STLP_DEBUG)
219 #  define list _STLP_NON_DBG_NAME(list)
220 #else
221 _STLP_MOVE_TO_STD_NAMESPACE
222 #endif
223
224 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
225 class list;
226
227 #if !defined (list)
228 _STLP_MOVE_TO_PRIV_NAMESPACE
229 #endif
230
231 // helper functions to reduce code duplication
232 template <class _Tp, class _Alloc, class _Predicate>
233 void _S_remove_if(list<_Tp, _Alloc>& __that, _Predicate __pred);
234
235 template <class _Tp, class _Alloc, class _BinaryPredicate>
236 void _S_unique(list<_Tp, _Alloc>& __that, _BinaryPredicate __binary_pred);
237
238 template <class _Tp, class _Alloc, class _StrictWeakOrdering>
239 void _S_merge(list<_Tp, _Alloc>& __that, list<_Tp, _Alloc>& __x,
240               _StrictWeakOrdering __comp);
241
242 template <class _Tp, class _Alloc, class _StrictWeakOrdering>
243 void _S_sort(list<_Tp, _Alloc>& __that, _StrictWeakOrdering __comp);
244
245 #if !defined (list)
246 _STLP_MOVE_TO_STD_NAMESPACE
247 #endif
248
249 template <class _Tp, class _Alloc>
250 class list : public _STLP_PRIV _List_base<_Tp, _Alloc>
251 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (list)
252            , public __stlport_class<list<_Tp, _Alloc> >
253 #endif
254 {
255   typedef _STLP_PRIV _List_base<_Tp, _Alloc> _Base;
256   typedef list<_Tp, _Alloc> _Self;
257   typedef _STLP_PRIV _List_node<_Tp> _Node;
258   typedef _STLP_PRIV _List_node_base _Node_base;
259 public:
260   typedef _Tp value_type;
261   typedef value_type* pointer;
262   typedef const value_type* const_pointer;
263   typedef value_type& reference;
264   typedef const value_type& const_reference;
265   typedef size_t size_type;
266   typedef ptrdiff_t difference_type;
267   _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
268   typedef typename _Base::allocator_type allocator_type;
269   typedef bidirectional_iterator_tag _Iterator_category;
270
271 public:
272   typedef _STLP_PRIV _List_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
273   typedef _STLP_PRIV _List_iterator<_Tp, _Const_traits<_Tp> >    const_iterator;
274   _STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS;
275
276 protected:
277 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
278   _Node_base* _M_create_node(const_reference __x = value_type()) {
279 #else
280   _Node_base* _M_create_node(const_reference __x) {
281 #endif /*!_STLP_DONT_SUP_DFLT_PARAM*/
282     _Node* __p = this->_M_node.allocate(1);
283     _STLP_TRY {
284       _Copy_Construct(&__p->_M_data, __x);
285     }
286     _STLP_UNWIND(this->_M_node.deallocate(__p, 1))
287     return __p;
288   }
289
290 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
291   _Node_base* _M_create_node() {
292     _Node* __p = this->_M_node.allocate(1);
293     _STLP_TRY {
294       _STLP_STD::_Construct(&__p->_M_data);
295     }
296     _STLP_UNWIND(this->_M_node.deallocate(__p, 1))
297     return __p;
298   }
299 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
300
301 public:
302 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
303   explicit list(size_type __n, const_reference __val = _STLP_DEFAULT_CONSTRUCTED(value_type),
304                 const allocator_type& __a = allocator_type())
305 #else
306   explicit list(size_type __n)
307     : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type())
308     { this->insert(begin(), __n, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
309   list(size_type __n, const_reference __val)
310     : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type())
311     { this->insert(begin(), __n, __val); }
312   list(size_type __n, const_reference __val, const allocator_type& __a)
313 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
314     : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
315     { this->insert(begin(), __n, __val); }
316
317 #if defined (_STLP_MEMBER_TEMPLATES)
318   // We don't need any dispatching tricks here, because insert does all of
319   // that anyway.
320   template <class _InputIterator>
321   list(_InputIterator __first, _InputIterator __last,
322        const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
323     : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
324   { _M_insert(begin(), __first, __last); }
325
326 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
327   template <class _InputIterator>
328   list(_InputIterator __first, _InputIterator __last)
329     : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type())
330   { _M_insert(begin(), __first, __last); }
331 #  endif
332 #else /* _STLP_MEMBER_TEMPLATES */
333   list(const value_type* __first, const value_type* __last,
334        const allocator_type& __a = allocator_type())
335     : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
336     { _M_insert(begin(), __first, __last); }
337   list(const_iterator __first, const_iterator __last,
338        const allocator_type& __a = allocator_type())
339     : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
340     { _M_insert(begin(), __first, __last); }
341 #endif /* _STLP_MEMBER_TEMPLATES */
342
343 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
344   explicit list(const allocator_type& __a = allocator_type())
345 #else
346   list()
347     : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type()) {}
348   list(const allocator_type& __a)
349 #endif
350     : _STLP_PRIV _List_base<_Tp, _Alloc>(__a) {}
351
352   list(const _Self& __x) : _STLP_PRIV _List_base<_Tp, _Alloc>(__x.get_allocator())
353   { _M_insert(begin(), __x.begin(), __x.end()); }
354
355   list(__move_source<_Self> src)
356     : _STLP_PRIV _List_base<_Tp, _Alloc>(__move_source<_Base>(src.get())) {}
357
358   ~list() {}
359
360   _Self& operator = (const _Self& __x);
361
362   iterator begin()                      { return iterator(this->_M_node._M_data._M_next); }
363   const_iterator begin() const          { return const_iterator(this->_M_node._M_data._M_next); }
364
365   iterator end()                        { return iterator(&this->_M_node._M_data); }
366   const_iterator end() const            { return const_iterator(__CONST_CAST(_Node_base*, &this->_M_node._M_data)); }
367
368   reverse_iterator rbegin()             { return reverse_iterator(end()); }
369   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
370
371   reverse_iterator rend()               { return reverse_iterator(begin()); }
372   const_reverse_iterator rend() const   { return const_reverse_iterator(begin()); }
373
374   size_type size() const {
375     size_type __result = distance(begin(), end());
376     return __result;
377   }
378   size_type max_size() const { return size_type(-1); }
379
380   reference front()             { return *begin(); }
381   const_reference front() const { return *begin(); }
382   reference back()              { return *(--end()); }
383   const_reference back() const  { return *(--end()); }
384
385 private:
386   void _M_swap_aux(_Self& __x) {
387     __x._M_node._M_swap_alloc(this->_M_node);
388     __x._M_node._M_data._M_next = this->_M_node._M_data._M_next;
389     __x._M_node._M_data._M_next->_M_prev = &__x._M_node._M_data;
390     __x._M_node._M_data._M_prev = this->_M_node._M_data._M_prev;
391     __x._M_node._M_data._M_prev->_M_next = &__x._M_node._M_data;
392     this->_M_empty_initialize();
393   }
394
395 public:
396   void swap(_Self& __x) {
397     if (__x.empty()) {
398       if (this->empty()) {
399         return;
400       }
401       this->_M_swap_aux(__x);
402     } else if (this->empty()) {
403       __x._M_swap_aux(*this);
404     } else {
405       this->_M_node.swap(__x._M_node);
406       _STLP_STD::swap(this->_M_node._M_data._M_prev->_M_next, __x._M_node._M_data._M_prev->_M_next);
407       _STLP_STD::swap(this->_M_node._M_data._M_next->_M_prev, __x._M_node._M_data._M_next->_M_prev);
408     }
409   }
410
411 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
412   iterator insert(iterator __pos, const_reference __x = value_type()) {
413 #else
414   iterator insert(iterator __pos, const_reference __x) {
415 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
416     _Node_base* __tmp = _M_create_node(__x);
417     _Node_base* __n = __pos._M_node;
418     _Node_base* __p = __n->_M_prev;
419     __tmp->_M_next = __n;
420     __tmp->_M_prev = __p;
421     __p->_M_next = __tmp;
422     __n->_M_prev = __tmp;
423     return iterator(__tmp);
424   }
425
426 private:
427 #if defined (_STLP_MEMBER_TEMPLATES)
428   template <class _InputIterator>
429   void _M_insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
430     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
431     _M_insert_dispatch(__pos, __first, __last, _Integral());
432   }
433
434   // Check whether it's an integral type.  If so, it's not an iterator.
435   template<class _Integer>
436   void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
437                           const __true_type& /*_IsIntegral*/) {
438     _M_fill_insert(__pos, __n, __x);
439   }
440   template <class _InputIter>
441   void _M_insert_dispatch(iterator __pos,
442                           _InputIter __first, _InputIter __last,
443                           const __false_type& /*_IsIntegral*/) {
444 #else /* _STLP_MEMBER_TEMPLATES */
445   void _M_insert(iterator __pos, const value_type* __first, const value_type* __last) {
446     for (; __first != __last; ++__first)
447       insert(__pos, *__first);
448   }
449   void _M_insert(iterator __pos, const_iterator __first, const_iterator __last) {
450 #endif /* _STLP_MEMBER_TEMPLATES */
451     //We use a temporary list to avoid the auto reference troubles (infinite loop)
452     for (; __first != __last; ++__first)
453       insert(__pos, *__first);
454   }
455
456 public:
457 #if defined (_STLP_MEMBER_TEMPLATES)
458   template <class _InputIterator>
459   void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
460     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
461     _M_splice_insert_dispatch(__pos, __first, __last, _Integral());
462   }
463
464 private:
465   // Check whether it's an integral type.  If so, it's not an iterator.
466   template<class _Integer>
467   void _M_splice_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
468                           const __true_type& /*_IsIntegral*/) {
469     _M_fill_insert(__pos, __n, __x);
470   }
471   template <class _InputIter>
472   void _M_splice_insert_dispatch(iterator __pos,
473                           _InputIter __first, _InputIter __last,
474                           const __false_type& /*_IsIntegral*/) {
475 #else /* _STLP_MEMBER_TEMPLATES */
476   void insert(iterator __pos, const value_type* __first, const value_type* __last) {
477     _Self __tmp(__first, __last, this->get_allocator());
478     splice(__pos, __tmp);
479   }
480   void insert(iterator __pos, const_iterator __first, const_iterator __last) {
481 #endif /* _STLP_MEMBER_TEMPLATES */
482     //We use a temporary list to avoid the auto reference troubles (infinite loop)
483     _Self __tmp(__first, __last, this->get_allocator());
484     splice(__pos, __tmp);
485   }
486
487 public:
488   void insert(iterator __pos, size_type __n, const_reference __x)
489   { _M_fill_insert(__pos, __n, __x); }
490
491 private:
492   void _M_fill_insert(iterator __pos, size_type __n, const_reference __x) {
493     for ( ; __n > 0; --__n)
494       insert(__pos, __x);
495   }
496
497 public:
498   void push_front(const_reference __x) { insert(begin(), __x); }
499   void push_back (const_reference __x) { insert(end(), __x); }
500
501 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
502   iterator insert(iterator __pos)
503   { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
504   void push_front() {insert(begin());}
505   void push_back() {insert(end());}
506 # endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
507
508   iterator erase(iterator __pos) {
509     _Node_base* __next_node = __pos._M_node->_M_next;
510     _Node_base* __prev_node = __pos._M_node->_M_prev;
511     _Node* __n = __STATIC_CAST(_Node*, __pos._M_node);
512     __prev_node->_M_next = __next_node;
513     __next_node->_M_prev = __prev_node;
514     _STLP_STD::_Destroy(&__n->_M_data);
515     this->_M_node.deallocate(__n, 1);
516     return iterator(__next_node);
517   }
518
519   iterator erase(iterator __first, iterator __last) {
520     while (__first != __last)
521       erase(__first++);
522     return __last;
523   }
524
525 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
526   void resize(size_type __new_size, const_reference __x = value_type());
527 #else
528   void resize(size_type __new_size, const_reference __x);
529   void resize(size_type __new_size)
530   { this->resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
531 #endif /*!_STLP_DONT_SUP_DFLT_PARAM*/
532
533   void pop_front() { erase(begin()); }
534   void pop_back() {
535     iterator __tmp = end();
536     erase(--__tmp);
537   }
538
539 public:
540   // assign(), a generalized assignment member function.  Two
541   // versions: one that takes a count, and one that takes a range.
542   // The range version is a member template, so we dispatch on whether
543   // or not the type is an integer.
544
545   void assign(size_type __n, const_reference __val) { _M_fill_assign(__n, __val); }
546
547   void _M_fill_assign(size_type __n, const_reference __val);
548
549 #if defined (_STLP_MEMBER_TEMPLATES)
550   template <class _InputIterator>
551   void assign(_InputIterator __first, _InputIterator __last) {
552     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
553     _M_assign_dispatch(__first, __last, _Integral());
554   }
555
556   template <class _Integer>
557   void _M_assign_dispatch(_Integer __n, _Integer __val,
558                           const __true_type& /*_IsIntegral*/) {
559     _M_fill_assign(__n, __val);
560   }
561
562   template <class _InputIterator>
563   void _M_assign_dispatch(_InputIterator __first2, _InputIterator __last2,
564                           const __false_type& /*_IsIntegral*/) {
565 #else
566   void assign(const value_type *__first2, const value_type *__last2) {
567     iterator __first1 = begin();
568     iterator __last1 = end();
569     for ( ; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
570       *__first1 = *__first2;
571     if (__first2 == __last2)
572       erase(__first1, __last1);
573     else
574       insert(__last1, __first2, __last2);
575   }
576   void assign(const_iterator __first2, const_iterator __last2) {
577 #endif /* _STLP_MEMBER_TEMPLATES */
578     iterator __first1 = begin();
579     iterator __last1 = end();
580     for ( ; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
581       *__first1 = *__first2;
582     if (__first2 == __last2)
583       erase(__first1, __last1);
584     else
585       insert(__last1, __first2, __last2);
586   }
587
588 public:
589   void splice(iterator __pos, _Self& __x) {
590     if (!__x.empty()) {
591       if (this->get_allocator() == __x.get_allocator()) {
592         _STLP_PRIV _List_global_inst::_Transfer(__pos._M_node, __x.begin()._M_node, __x.end()._M_node);
593       }
594       else {
595         insert(__pos, __x.begin(), __x.end());
596         __x.clear();
597       }
598     }
599   }
600   void splice(iterator __pos, _Self& __x, iterator __i) {
601     iterator __j = __i;
602     ++__j;
603     if (__pos == __i || __pos == __j) return;
604     if (this->get_allocator() == __x.get_allocator()) {
605       _STLP_PRIV _List_global_inst::_Transfer(__pos._M_node, __i._M_node, __j._M_node);
606     }
607     else {
608       insert(__pos, *__i);
609       __x.erase(__i);
610     }
611   }
612   void splice(iterator __pos, _Self& __x, iterator __first, iterator __last) {
613     if (__first != __last) {
614       if (this->get_allocator() == __x.get_allocator()) {
615         _STLP_PRIV _List_global_inst::_Transfer(__pos._M_node, __first._M_node, __last._M_node);
616       }
617       else {
618         insert(__pos, __first, __last);
619         __x.erase(__first, __last);
620       }
621     }
622   }
623
624   void remove(const_reference __val) {
625     iterator __first = begin();
626     iterator __last = end();
627     while (__first != __last) {
628       iterator __next = __first;
629       ++__next;
630       if (__val == *__first) erase(__first);
631       __first = __next;
632     }
633   }
634
635   void unique()
636   { _STLP_PRIV _S_unique(*this, equal_to<value_type>()); }
637
638   void merge(_Self& __x)
639   { _STLP_PRIV _S_merge(*this, __x, less<value_type>()); }
640
641   void reverse() {
642     _Node_base* __p = &this->_M_node._M_data;
643     _Node_base* __tmp = __p;
644     do {
645       _STLP_STD::swap(__tmp->_M_next, __tmp->_M_prev);
646       __tmp = __tmp->_M_prev;     // Old next node is now prev.
647     } while (__tmp != __p);
648   }
649
650   void sort()
651   { _STLP_PRIV _S_sort(*this, less<value_type>()); }
652
653 #if defined (_STLP_MEMBER_TEMPLATES)
654   template <class _Predicate>
655   void remove_if(_Predicate __pred)
656   { _STLP_PRIV _S_remove_if(*this, __pred); }
657   template <class _BinaryPredicate>
658   void unique(_BinaryPredicate __binary_pred)
659   { _STLP_PRIV _S_unique(*this, __binary_pred); }
660
661   template <class _StrictWeakOrdering>
662   void merge(_Self& __x,
663              _StrictWeakOrdering __comp) {
664     _STLP_PRIV _S_merge(*this, __x, __comp);
665   }
666
667   template <class _StrictWeakOrdering>
668   void sort(_StrictWeakOrdering __comp)
669   { _STLP_PRIV _S_sort(*this, __comp); }
670 #endif /* _STLP_MEMBER_TEMPLATES */
671 };
672
673 #if defined (list)
674 #  undef list
675 _STLP_MOVE_TO_STD_NAMESPACE
676 #endif
677
678 _STLP_END_NAMESPACE
679
680 #if !defined (_STLP_LINK_TIME_INSTANTIATION)
681 #  include <stl/_list.c>
682 #endif
683
684 #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
685 #  include <stl/pointers/_list.h>
686 #endif
687
688 #if defined (_STLP_DEBUG)
689 #  include <stl/debug/_list.h>
690 #endif
691
692 _STLP_BEGIN_NAMESPACE
693
694 template <class _Tp, class _Alloc>
695 _STLP_INLINE_LOOP bool  _STLP_CALL
696 operator==(const list<_Tp,_Alloc>& __x, const list<_Tp,_Alloc>& __y) {
697   typedef typename list<_Tp,_Alloc>::const_iterator const_iterator;
698   const_iterator __end1 = __x.end();
699   const_iterator __end2 = __y.end();
700
701   const_iterator __i1 = __x.begin();
702   const_iterator __i2 = __y.begin();
703   while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) {
704     ++__i1;
705     ++__i2;
706   }
707   return __i1 == __end1 && __i2 == __end2;
708 }
709
710 #define _STLP_EQUAL_OPERATOR_SPECIALIZED
711 #define _STLP_TEMPLATE_HEADER    template <class _Tp, class _Alloc>
712 #define _STLP_TEMPLATE_CONTAINER list<_Tp, _Alloc>
713 #include <stl/_relops_cont.h>
714 #undef _STLP_TEMPLATE_CONTAINER
715 #undef _STLP_TEMPLATE_HEADER
716 #undef _STLP_EQUAL_OPERATOR_SPECIALIZED
717
718 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
719 template <class _Tp, class _Alloc>
720 struct __move_traits<list<_Tp, _Alloc> > {
721   typedef __stlp_movable implemented;
722   typedef typename __move_traits<_Alloc>::complete complete;
723 };
724 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
725
726 _STLP_END_NAMESPACE
727
728 #endif /* _STLP_INTERNAL_LIST_IMPL_H */
729
730 // Local Variables:
731 // mode:C++
732 // End: