epoc32/include/stdapis/stlport/stl/_slist.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 0 061f57f2323e
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /*
     2  *
     3  * Copyright (c) 1996,1997
     4  * Silicon Graphics Computer Systems, Inc.
     5  *
     6  * Copyright (c) 1997
     7  * Moscow Center for SPARC Technology
     8  *
     9  * Copyright (c) 1999 
    10  * Boris Fomitchev
    11  *
    12  * This material is provided "as is", with absolutely no warranty expressed
    13  * or implied. Any use is at your own risk.
    14  *
    15  * Permission to use or copy this software for any purpose is hereby granted 
    16  * without fee, provided the above notices are retained on all copies.
    17  * Permission to modify the code and to distribute modified code is granted,
    18  * provided the above notices are retained, and a notice that the code was
    19  * modified is included with the above copyright notice.
    20  *
    21  */
    22 
    23 /* NOTE: This is an internal header file, included by other STL headers.
    24  *   You should not attempt to use it directly.
    25  */
    26 
    27 #ifndef _STLP_INTERNAL_SLIST_H
    28 #define _STLP_INTERNAL_SLIST_H
    29 
    30 
    31 # ifndef _STLP_INTERNAL_ALGOBASE_H
    32 #  include <stl/_algobase.h>
    33 # endif
    34 
    35 # ifndef _STLP_INTERNAL_ALLOC_H
    36 #  include <stl/_alloc.h>
    37 # endif
    38 
    39 # ifndef _STLP_INTERNAL_ITERATOR_H
    40 #  include <stl/_iterator.h>
    41 # endif
    42 
    43 # ifndef _STLP_INTERNAL_CONSTRUCT_H
    44 #  include <stl/_construct.h>
    45 # endif
    46 
    47 # ifndef _STLP_INTERNAL_SLIST_BASE_H
    48 #  include <stl/_slist_base.h>
    49 # endif
    50 
    51 # undef slist
    52 # define  slist  __WORKAROUND_DBG_RENAME(slist)
    53 
    54 _STLP_BEGIN_NAMESPACE 
    55 
    56 template <class _Tp>
    57 struct _Slist_node : public _Slist_node_base
    58 {
    59   _Tp _M_data;
    60   __TRIVIAL_STUFF(_Slist_node)
    61 };
    62 
    63 struct _Slist_iterator_base {
    64 
    65   typedef size_t               size_type;
    66   typedef ptrdiff_t            difference_type;
    67   typedef forward_iterator_tag iterator_category;
    68 
    69   _Slist_node_base* _M_node;
    70 
    71   _Slist_iterator_base(_Slist_node_base* __x) : _M_node(__x) {}
    72 
    73   void _M_incr() { 
    74 //    _STLP_VERBOSE_ASSERT(_M_node != 0, _StlMsg_INVALID_ADVANCE)
    75     _M_node = _M_node->_M_next; 
    76   }
    77   bool operator==(const _Slist_iterator_base& __y ) const { 
    78     return _M_node == __y._M_node; 
    79   }
    80   bool operator!=(const _Slist_iterator_base& __y ) const { 
    81     return _M_node != __y._M_node; 
    82   }
    83 };
    84 
    85 # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
    86 inline ptrdiff_t* _STLP_CALL distance_type(const _Slist_iterator_base&) { return 0; }
    87 inline forward_iterator_tag _STLP_CALL iterator_category(const _Slist_iterator_base&) { return forward_iterator_tag(); }
    88 #endif
    89 
    90 template <class _Tp, class _Traits>
    91 struct _Slist_iterator : public _Slist_iterator_base
    92 {
    93   typedef _Tp value_type;
    94   typedef typename _Traits::pointer    pointer;
    95   typedef typename _Traits::reference  reference;
    96   typedef forward_iterator_tag iterator_category;
    97   typedef size_t size_type;
    98   typedef ptrdiff_t difference_type;
    99   
   100   typedef _Slist_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
   101   typedef _Slist_iterator<_Tp, _Const_traits<_Tp> >    const_iterator;
   102   typedef _Slist_iterator<_Tp, _Traits>                       _Self;
   103 
   104   typedef _Slist_node<value_type> _Node;
   105 
   106   _Slist_iterator(_Node* __x) : _Slist_iterator_base(__x) {}
   107   _Slist_iterator() : _Slist_iterator_base(0) {}
   108   _Slist_iterator(const iterator& __x) : _Slist_iterator_base(__x._M_node) {}
   109 
   110   reference operator*() const { return ((_Node*) _M_node)->_M_data; }
   111 
   112   _STLP_DEFINE_ARROW_OPERATOR
   113 
   114   _Self& operator++()
   115   {
   116     _M_incr();
   117     return *this;
   118   }
   119   _Self operator++(int)
   120   {
   121     _Self __tmp = *this;
   122     _M_incr();
   123     return __tmp;
   124   }
   125 };
   126 
   127 #ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
   128 template <class _Tp, class _Traits>
   129 inline _Tp* _STLP_CALL value_type(const _Slist_iterator<_Tp, _Traits>&) { return (_Tp*)0; }
   130 #endif /* OLD_QUERIES */
   131 
   132 // Base class that encapsulates details of allocators and simplifies EH
   133 
   134 template <class _Tp, class _Alloc> 
   135 struct _Slist_base 
   136 {
   137   _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
   138   typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type;
   139   typedef _Slist_node<_Tp> _Node;
   140 
   141   _Slist_base(const allocator_type& __a) : 
   142     _M_head(_STLP_CONVERT_ALLOCATOR(__a, _Node), _Slist_node_base() ) { 
   143     _M_head._M_data._M_next = 0; 
   144   }
   145   ~_Slist_base() { _M_erase_after(&_M_head._M_data, 0); }
   146 
   147 protected:
   148   typedef typename _Alloc_traits<_Node,_Alloc>::allocator_type _M_node_allocator_type;
   149 
   150   _Slist_node_base* _M_erase_after(_Slist_node_base* __pos)
   151   {
   152     _Node* __next = (_Node*) (__pos->_M_next);
   153     _Slist_node_base* __next_next = __next->_M_next;
   154     __pos->_M_next = __next_next;
   155     _STLP_STD::_Destroy(&__next->_M_data);
   156     _M_head.deallocate(__next,1);
   157     return __next_next;
   158   }
   159   _Slist_node_base* _M_erase_after(_Slist_node_base*, _Slist_node_base*);
   160 
   161 public:
   162   allocator_type get_allocator() const { 
   163     return _STLP_CONVERT_ALLOCATOR((const _M_node_allocator_type&)_M_head, _Tp); 
   164   }
   165   _STLP_alloc_proxy<_Slist_node_base, _Node, _M_node_allocator_type> _M_head;
   166 };  
   167 
   168 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
   169 class slist : public _Slist_base<_Tp,_Alloc>
   170 {
   171 private:
   172   typedef _Slist_base<_Tp,_Alloc> _Base;
   173   typedef slist<_Tp,_Alloc> _Self;
   174 public:
   175   typedef _Tp                value_type;
   176   typedef value_type*       pointer;
   177   typedef const value_type* const_pointer;
   178   typedef value_type&       reference;
   179   typedef const value_type& const_reference;
   180   typedef size_t            size_type;
   181   typedef ptrdiff_t         difference_type;
   182   typedef forward_iterator_tag _Iterator_category;
   183 
   184   typedef _Slist_iterator<_Tp, _Nonconst_traits<_Tp> >  iterator;
   185   typedef _Slist_iterator<_Tp, _Const_traits<_Tp> >     const_iterator;
   186 
   187   _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
   188   typedef typename _Base::allocator_type allocator_type;
   189 
   190 
   191 private:
   192   typedef _Slist_node<_Tp>      _Node;
   193   typedef _Slist_node_base      _Node_base;
   194   typedef _Slist_iterator_base  _Iterator_base;
   195 
   196   _Node* _M_create_node(const value_type& __x) {
   197     _Node* __node = this->_M_head.allocate(1);
   198     _STLP_TRY {
   199       _Construct(&__node->_M_data, __x);
   200       __node->_M_next = 0;
   201     }
   202     _STLP_UNWIND(this->_M_head.deallocate(__node, 1));
   203     return __node;
   204   }
   205   
   206   _Node* _M_create_node() {
   207     _Node* __node = this->_M_head.allocate(1);
   208     _STLP_TRY {
   209       _Construct(&__node->_M_data);
   210       __node->_M_next = 0;
   211     }
   212     _STLP_UNWIND(this->_M_head.deallocate(__node, 1));
   213     return __node;
   214   }
   215 
   216 public:
   217   allocator_type get_allocator() const { return _Base::get_allocator(); }
   218 
   219   explicit slist(const allocator_type& __a = allocator_type()) : _Slist_base<_Tp,_Alloc>(__a) {
   220     _STLP_POP_IF_CHECK
   221   }
   222 
   223   slist(size_type __n, const value_type& __x,
   224         const allocator_type& __a =  allocator_type()) : _Slist_base<_Tp,_Alloc>(__a)
   225     { 
   226       _STLP_PUSH_CLEANUP_ITEM(_Base, this) 
   227       _M_insert_after_fill(&this->_M_head._M_data, __n, __x); 
   228       _STLP_POP_CLEANUP_ITEM
   229     }
   230 
   231   explicit slist(size_type __n) : _Slist_base<_Tp,_Alloc>(allocator_type())
   232     { 
   233 # ifdef _STLP_USE_TRAP_LEAVE
   234       _STLP_PUSH_CLEANUP_ITEM(_Base, this) 
   235       _Tp __p;
   236       _STLP_PUSH_CLEANUP_ITEM(_Tp, &__p) 
   237       _M_insert_after_fill(&this->_M_head._M_data, __n, __p);
   238        // unconditional for __p
   239       CleanupStack::Pop();
   240       _STLP_POP_CLEANUP_ITEM
   241 # else
   242       _M_insert_after_fill(&this->_M_head._M_data, __n, value_type()); 
   243 # endif
   244     }
   245 
   246 #ifdef _STLP_MEMBER_TEMPLATES
   247   // We don't need any dispatching tricks here, because _M_insert_after_range
   248   // already does them.
   249   template <class _InputIterator>
   250   slist(_InputIterator __first, _InputIterator __last,
   251         const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) : 
   252     _Slist_base<_Tp,_Alloc>(__a)
   253   { 
   254      _STLP_PUSH_CLEANUP_ITEM(_Base, this) 
   255      _M_insert_after_range(&this->_M_head._M_data, __first, __last); 
   256      _STLP_POP_CLEANUP_ITEM
   257   }
   258 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
   259   // VC++ needs this crazyness
   260   template <class _InputIterator>
   261   slist(_InputIterator __first, _InputIterator __last) :
   262     _Slist_base<_Tp,_Alloc>(allocator_type())
   263   { 
   264     _STLP_PUSH_CLEANUP_ITEM(_Base, this) 
   265     _M_insert_after_range(&this->_M_head._M_data, __first, __last); 
   266     _STLP_POP_CLEANUP_ITEM
   267   }
   268 # endif  
   269 #else /* _STLP_MEMBER_TEMPLATES */
   270   slist(const_iterator __first, const_iterator __last,
   271         const allocator_type& __a =  allocator_type() ) :
   272     _Slist_base<_Tp,_Alloc>(__a)
   273     { 
   274       _STLP_PUSH_CLEANUP_ITEM(_Base, this) 
   275       _M_insert_after_range(&this->_M_head._M_data, __first, __last); 
   276       _STLP_POP_CLEANUP_ITEM
   277     }
   278   slist(const value_type* __first, const value_type* __last,
   279         const allocator_type& __a =  allocator_type()) : 
   280     _Slist_base<_Tp,_Alloc>(__a)
   281     { 
   282       _STLP_PUSH_CLEANUP_ITEM(_Base, this) 
   283       _M_insert_after_range(&this->_M_head._M_data, __first, __last); 
   284       _STLP_POP_CLEANUP_ITEM
   285     }
   286 #endif /* _STLP_MEMBER_TEMPLATES */
   287 
   288   slist(const _Self& __x) : _Slist_base<_Tp,_Alloc>(__x.get_allocator())
   289   {  
   290     _STLP_PUSH_CLEANUP_ITEM(_Base, this) 
   291     _M_insert_after_range(&this->_M_head._M_data, __x.begin(), __x.end()); 
   292     _STLP_POP_CLEANUP_ITEM
   293   }
   294 
   295   _Self& operator= (const _Self& __x);
   296 
   297   ~slist() {}
   298 
   299 #ifdef _STLP_USE_TRAP_LEAVE
   300 public:
   301   static void* operator new (size_t __n, TLeave) { return _STLP_StackHelper<bool>::_NewLC(__n); }
   302   static void* operator new (size_t __n) { return _STLP_StackHelper<bool>::_NewLC(__n); }
   303 #endif
   304 
   305 public:
   306   // assign(), a generalized assignment member function.  Two
   307   // versions: one that takes a count, and one that takes a range.
   308   // The range version is a member template, so we dispatch on whether
   309   // or not the type is an integer.
   310 
   311   void assign(size_type __n, const _Tp& __val)
   312     { _M_fill_assign(__n, __val); }
   313 
   314   void _M_fill_assign(size_type __n, const _Tp& __val);
   315 
   316 #ifdef _STLP_MEMBER_TEMPLATES
   317 
   318   template <class _InputIterator>
   319   void assign(_InputIterator __first, _InputIterator __last) {
   320     typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
   321     _M_assign_dispatch(__first, __last, _Integral());
   322   }
   323 
   324   template <class _Integer>
   325   void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&)
   326     { _M_fill_assign((size_type) __n, (_Tp) __val); }
   327 
   328   template <class _InputIter>
   329   void
   330   _M_assign_dispatch(_InputIter __first, _InputIter __last,
   331 		     const __false_type&) {
   332     _Node_base* __prev = &this->_M_head._M_data;
   333     _Node* __node = (_Node*) this->_M_head._M_data._M_next;
   334     while (__node != 0 && __first != __last) {
   335       __node->_M_data = *__first;
   336       __prev = __node;
   337       __node = (_Node*) __node->_M_next;
   338       ++__first;
   339     }
   340     if (__first != __last)
   341       _M_insert_after_range(__prev, __first, __last);
   342     else
   343       this->_M_erase_after(__prev, 0);
   344   }
   345 #endif /* _STLP_MEMBER_TEMPLATES */
   346 
   347 public:
   348 
   349   // Experimental new feature: before_begin() returns a
   350   // non-dereferenceable iterator that, when incremented, yields
   351   // begin().  This iterator may be used as the argument to
   352   // insert_after, erase_after, etc.  Note that even for an empty 
   353   // slist, before_begin() is not the same iterator as end().  It 
   354   // is always necessary to increment before_begin() at least once to
   355   // obtain end().
   356   iterator before_begin() { return iterator((_Node*) &this->_M_head._M_data); }
   357   const_iterator before_begin() const
   358     { return const_iterator((_Node*) &this->_M_head._M_data); }
   359 
   360   iterator begin() { return iterator((_Node*)this->_M_head._M_data._M_next); }
   361   const_iterator begin() const 
   362     { return const_iterator((_Node*)this->_M_head._M_data._M_next);}
   363 
   364   iterator end() { return iterator(0); }
   365   const_iterator end() const { return const_iterator(0); }
   366 
   367   size_type size() const { return _Sl_global_inst::size(this->_M_head._M_data._M_next); }
   368   
   369   size_type max_size() const { return size_type(-1); }
   370 
   371   bool empty() const { return this->_M_head._M_data._M_next == 0; }
   372 
   373   void swap(_Self& __x) { 
   374     _STLP_STD::swap(this->_M_head, __x._M_head); 
   375   }
   376 
   377 public:
   378   reference front() { return ((_Node*) this->_M_head._M_data._M_next)->_M_data; }
   379   const_reference front() const 
   380     { return ((_Node*) this->_M_head._M_data._M_next)->_M_data; }
   381   void push_front(const value_type& __x)   {
   382     __slist_make_link(&this->_M_head._M_data, _M_create_node(__x));
   383   }
   384 
   385 # ifndef _STLP_NO_ANACHRONISMS
   386   void push_front() { __slist_make_link(&this->_M_head._M_data, _M_create_node());}
   387 # endif
   388 
   389   void pop_front() {
   390     _Node* __node = (_Node*) this->_M_head._M_data._M_next;
   391     this->_M_head._M_data._M_next = __node->_M_next;
   392     _STLP_STD::_Destroy(&__node->_M_data);
   393     this->_M_head.deallocate(__node, 1);
   394   }
   395 
   396   iterator previous(const_iterator __pos) {
   397     return iterator((_Node*) _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node));
   398   }
   399   const_iterator previous(const_iterator __pos) const {
   400     return const_iterator((_Node*) _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node));
   401   }
   402 
   403 private:
   404   _Node* _M_insert_after(_Node_base* __pos, const value_type& __x) {
   405     return (_Node*) (__slist_make_link(__pos, _M_create_node(__x)));
   406   }
   407 
   408   _Node* _M_insert_after(_Node_base* __pos) {
   409     return (_Node*) (__slist_make_link(__pos, _M_create_node()));
   410   }
   411 
   412   void _M_insert_after_fill(_Node_base* __pos,
   413                             size_type __n, const value_type& __x) {
   414     for (size_type __i = 0; __i < __n; ++__i)
   415       __pos = __slist_make_link(__pos, _M_create_node(__x));
   416   }
   417 
   418 #ifdef _STLP_MEMBER_TEMPLATES
   419 
   420   // Check whether it's an integral type.  If so, it's not an iterator.
   421   template <class _InIter>
   422   void _M_insert_after_range(_Node_base* __pos, 
   423                              _InIter __first, _InIter __last) {
   424     typedef typename _Is_integer<_InIter>::_Integral _Integral;
   425     _M_insert_after_range(__pos, __first, __last, _Integral());
   426   }
   427 
   428   template <class _Integer>
   429   void _M_insert_after_range(_Node_base* __pos, _Integer __n, _Integer __x,
   430                              const __true_type&) {
   431     _M_insert_after_fill(__pos, __n, __x);
   432   }
   433 
   434   template <class _InIter>
   435   void _M_insert_after_range(_Node_base* __pos,
   436                              _InIter __first, _InIter __last,
   437                              const __false_type&) {
   438     while (__first != __last) {
   439       __pos = __slist_make_link(__pos, _M_create_node(*__first));
   440       ++__first;
   441     }
   442   }
   443 
   444 #else /* _STLP_MEMBER_TEMPLATES */
   445 
   446   void _M_insert_after_range(_Node_base* __pos,
   447                              const_iterator __first, const_iterator __last) {
   448     while (__first != __last) {
   449       __pos = __slist_make_link(__pos, _M_create_node(*__first));
   450       ++__first;
   451     }
   452   }
   453   void _M_insert_after_range(_Node_base* __pos,
   454                              const value_type* __first,
   455                              const value_type* __last) {
   456     while (__first != __last) {
   457       __pos = __slist_make_link(__pos, _M_create_node(*__first));
   458       ++__first;
   459     }
   460   }
   461 
   462 #endif /* _STLP_MEMBER_TEMPLATES */
   463 
   464 public:
   465 
   466   iterator insert_after(iterator __pos, const value_type& __x) {
   467     return iterator(_M_insert_after(__pos._M_node, __x));
   468   }
   469 
   470   iterator insert_after(iterator __pos) {
   471     return insert_after(__pos, value_type());
   472   }
   473 
   474   void insert_after(iterator __pos, size_type __n, const value_type& __x) {
   475     _M_insert_after_fill(__pos._M_node, __n, __x);
   476   }
   477 
   478 #ifdef _STLP_MEMBER_TEMPLATES
   479 
   480   // We don't need any dispatching tricks here, because _M_insert_after_range
   481   // already does them.
   482   template <class _InIter>
   483   void insert_after(iterator __pos, _InIter __first, _InIter __last) {
   484     _M_insert_after_range(__pos._M_node, __first, __last);
   485   }
   486 
   487 #else /* _STLP_MEMBER_TEMPLATES */
   488 
   489   void insert_after(iterator __pos,
   490                     const_iterator __first, const_iterator __last) {
   491     _M_insert_after_range(__pos._M_node, __first, __last);
   492   }
   493   void insert_after(iterator __pos,
   494                     const value_type* __first, const value_type* __last) {
   495     _M_insert_after_range(__pos._M_node, __first, __last);
   496   }
   497 
   498 #endif /* _STLP_MEMBER_TEMPLATES */
   499 
   500   iterator insert(iterator __pos, const value_type& __x) {
   501     return iterator(_M_insert_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
   502                     __x));
   503   }
   504 
   505   iterator insert(iterator __pos) {
   506     return iterator(_M_insert_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
   507                                     value_type()));
   508   }
   509 
   510   void insert(iterator __pos, size_type __n, const value_type& __x) {
   511     _M_insert_after_fill(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), __n, __x);
   512   } 
   513     
   514 #ifdef _STLP_MEMBER_TEMPLATES
   515 
   516   // We don't need any dispatching tricks here, because _M_insert_after_range
   517   // already does them.
   518   template <class _InIter>
   519   void insert(iterator __pos, _InIter __first, _InIter __last) {
   520     _M_insert_after_range(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), 
   521                           __first, __last);
   522   }
   523 
   524 #else /* _STLP_MEMBER_TEMPLATES */
   525 
   526   void insert(iterator __pos, const_iterator __first, const_iterator __last) {
   527     _M_insert_after_range(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), 
   528                           __first, __last);
   529   }
   530   void insert(iterator __pos, const value_type* __first, 
   531                               const value_type* __last) {
   532     _M_insert_after_range(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), 
   533                           __first, __last);
   534   }
   535 
   536 #endif /* _STLP_MEMBER_TEMPLATES */
   537 
   538 
   539 public:
   540   iterator erase_after(iterator __pos) {
   541     return iterator((_Node*) this->_M_erase_after(__pos._M_node));
   542   }
   543   iterator erase_after(iterator __before_first, iterator __last) {
   544     return iterator((_Node*) this->_M_erase_after(__before_first._M_node, 
   545                                             __last._M_node));
   546   } 
   547 
   548   iterator erase(iterator __pos) {
   549     return iterator((_Node*) this->_M_erase_after(_Sl_global_inst::__previous(&this->_M_head._M_data, 
   550                                                     __pos._M_node)));
   551   }
   552   iterator erase(iterator __first, iterator __last) {
   553     return iterator((_Node*) this->_M_erase_after(
   554       _Sl_global_inst::__previous(&this->_M_head._M_data, __first._M_node), __last._M_node));
   555   }
   556 
   557   void resize(size_type new_size, const _Tp& __x);
   558   void resize(size_type new_size) { resize(new_size, _Tp()); }
   559   void clear() {
   560     this->_M_erase_after(&this->_M_head._M_data, 0); 
   561   }
   562 
   563 public:
   564   // Moves the range [__before_first + 1, __before_last + 1) to *this,
   565   //  inserting it immediately after __pos.  This is constant time.
   566   void splice_after(iterator __pos, 
   567                     iterator __before_first, iterator __before_last)
   568   {
   569     if (__before_first != __before_last) {
   570       _Sl_global_inst::__splice_after(__pos._M_node, __before_first._M_node, 
   571                            __before_last._M_node);
   572     }
   573   }
   574 
   575   // Moves the element that follows __prev to *this, inserting it immediately
   576   //  after __pos.  This is constant time.
   577   void splice_after(iterator __pos, iterator __prev)
   578   {
   579     _Sl_global_inst::__splice_after(__pos._M_node,
   580                          __prev._M_node, __prev._M_node->_M_next);
   581   }
   582 
   583   // Removes all of the elements from the list __x to *this, inserting
   584   // them immediately after __pos.  __x must not be *this.  Complexity:
   585   // linear in __x.size().
   586   void splice_after(iterator __pos, _Self& __x)
   587   {
   588     _Sl_global_inst::__splice_after(__pos._M_node, &__x._M_head._M_data);
   589   }
   590 
   591   // Linear in distance(begin(), __pos), and linear in __x.size().
   592   void splice(iterator __pos, _Self& __x) {
   593     if (__x._M_head._M_data._M_next)
   594       _Sl_global_inst::__splice_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
   595                            &__x._M_head._M_data, _Sl_global_inst::__previous(&__x._M_head._M_data, 0));
   596   }
   597 
   598   // Linear in distance(begin(), __pos), and in distance(__x.begin(), __i).
   599   void splice(iterator __pos, _Self& __x, iterator __i) {
   600     _Sl_global_inst::__splice_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
   601                          _Sl_global_inst::__previous(&__x._M_head._M_data, __i._M_node),
   602                          __i._M_node);
   603   }
   604 
   605   // Linear in distance(begin(), __pos), in distance(__x.begin(), __first),
   606   // and in distance(__first, __last).
   607   void splice(iterator __pos, _Self& __x, iterator __first, iterator __last)
   608   {
   609     if (__first != __last)
   610       _Sl_global_inst::__splice_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
   611                            _Sl_global_inst::__previous(&__x._M_head._M_data, __first._M_node),
   612                            _Sl_global_inst::__previous(__first._M_node, __last._M_node));
   613   }
   614 
   615 public:
   616   void reverse() { 
   617     if (this->_M_head._M_data._M_next)
   618       this->_M_head._M_data._M_next = _Sl_global_inst::__reverse(this->_M_head._M_data._M_next);
   619   }
   620 
   621   void remove(const _Tp& __val); 
   622   void unique(); 
   623   void merge(_Self& __x);
   624   void sort();     
   625 
   626 #ifdef _STLP_MEMBER_TEMPLATES
   627   template <class _Predicate>
   628   void remove_if(_Predicate __pred) {
   629     _Node_base* __cur = &this->_M_head._M_data;
   630     while (__cur->_M_next) {
   631       if (__pred(((_Node*) __cur->_M_next)->_M_data))
   632 	this->_M_erase_after(__cur);
   633       else
   634 	__cur = __cur->_M_next;
   635     }
   636   }
   637 
   638   template <class _BinaryPredicate> 
   639   void unique(_BinaryPredicate __pred) {
   640     _Node* __cur = (_Node*) this->_M_head._M_data._M_next;
   641     if (__cur) {
   642       while (__cur->_M_next) {
   643 	if (__pred(((_Node*)__cur)->_M_data, 
   644 		   ((_Node*)(__cur->_M_next))->_M_data))
   645 	  this->_M_erase_after(__cur);
   646 	else
   647 	  __cur = (_Node*) __cur->_M_next;
   648       }
   649     }
   650   }
   651 
   652   template <class _StrictWeakOrdering>
   653   void merge(slist<_Tp,_Alloc>& __x,
   654 	     _StrictWeakOrdering __comp) {
   655     _Node_base* __n1 = &this->_M_head._M_data;
   656     while (__n1->_M_next && __x._M_head._M_data._M_next) {
   657       if (__comp(((_Node*) __x._M_head._M_data._M_next)->_M_data,
   658 		 ((_Node*)       __n1->_M_next)->_M_data))
   659 	_Sl_global_inst::__splice_after(__n1, &__x._M_head._M_data, __x._M_head._M_data._M_next);
   660       __n1 = __n1->_M_next;
   661     }
   662     if (__x._M_head._M_data._M_next) {
   663       __n1->_M_next = __x._M_head._M_data._M_next;
   664       __x._M_head._M_data._M_next = 0;
   665     }
   666   }
   667 
   668   template <class _StrictWeakOrdering> 
   669   void sort(_StrictWeakOrdering __comp) {
   670     if (this->_M_head._M_data._M_next && this->_M_head._M_data._M_next->_M_next) {
   671       slist __carry;
   672       slist __counter[64];
   673       int __fill = 0;
   674       while (!empty()) {
   675 	_Sl_global_inst::__splice_after(&__carry._M_head._M_data, &this->_M_head._M_data, this->_M_head._M_data._M_next);
   676 	int __i = 0;
   677 	while (__i < __fill && !__counter[__i].empty()) {
   678 	  __counter[__i].merge(__carry, __comp);
   679 	  __carry.swap(__counter[__i]);
   680 	  ++__i;
   681 	}
   682 	__carry.swap(__counter[__i]);
   683 	if (__i == __fill)
   684 	  ++__fill;
   685       }
   686       
   687       for (int __i = 1; __i < __fill; ++__i)
   688 	__counter[__i].merge(__counter[__i-1], __comp);
   689       this->swap(__counter[__fill-1]);
   690     }
   691   }
   692 #endif /* _STLP_MEMBER_TEMPLATES */
   693 
   694 };
   695 
   696 template <class _Tp, class _Alloc>
   697 inline bool  _STLP_CALL
   698 operator==(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2)
   699 {
   700   typedef typename slist<_Tp,_Alloc>::const_iterator const_iterator;
   701   const_iterator __end1 = _SL1.end();
   702   const_iterator __end2 = _SL2.end();
   703 
   704   const_iterator __i1 = _SL1.begin();
   705   const_iterator __i2 = _SL2.begin();
   706   while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) {
   707     ++__i1;
   708     ++__i2;
   709    }
   710   return __i1 == __end1 && __i2 == __end2;
   711 }
   712 
   713 # define _STLP_EQUAL_OPERATOR_SPECIALIZED
   714 # define _STLP_TEMPLATE_HEADER    template <class _Tp, class _Alloc>
   715 # define _STLP_TEMPLATE_CONTAINER slist<_Tp, _Alloc>
   716 # include <stl/_relops_cont.h>
   717 # undef _STLP_TEMPLATE_CONTAINER
   718 # undef _STLP_TEMPLATE_HEADER
   719 # undef _STLP_EQUAL_OPERATOR_SPECIALIZED
   720 
   721 _STLP_END_NAMESPACE
   722 
   723 # if !defined (_STLP_LINK_TIME_INSTANTIATION)
   724 #  include <stl/_slist.c>
   725 # endif
   726 
   727 #  undef  slist
   728 #  define __slist__ __FULL_NAME(slist)
   729 
   730 #if defined (_STLP_DEBUG) && !defined (_STLP_INTERNAL_DBG_SLIST_H)
   731 # include <stl/debug/_slist.h>
   732 #endif
   733 
   734 _STLP_BEGIN_NAMESPACE
   735 // Specialization of insert_iterator so that insertions will be constant
   736 // time rather than linear time.
   737 
   738 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
   739 
   740 template <class _Tp, class _Alloc>
   741 class insert_iterator<slist<_Tp, _Alloc> > {
   742 protected:
   743   typedef slist<_Tp, _Alloc> _Container;
   744   _Container* container;
   745   typename _Container::iterator iter;
   746 public:
   747   typedef _Container          container_type;
   748   typedef output_iterator_tag iterator_category;
   749   typedef void                value_type;
   750   typedef void                difference_type;
   751   typedef void                pointer;
   752   typedef void                reference;
   753 
   754   insert_iterator(_Container& __x, typename _Container::iterator __i) 
   755     : container(&__x) {
   756     if (__i == __x.begin())
   757       iter = __x.before_begin();
   758     else
   759       iter = __x.previous(__i);
   760   }
   761 
   762   insert_iterator<_Container>&
   763   operator=(const typename _Container::value_type& __val) { 
   764     iter = container->insert_after(iter, __val);
   765     return *this;
   766   }
   767   insert_iterator<_Container>& operator*() { return *this; }
   768   insert_iterator<_Container>& operator++() { return *this; }
   769   insert_iterator<_Container>& operator++(int) { return *this; }
   770 };
   771 
   772 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
   773 
   774 _STLP_END_NAMESPACE
   775 
   776 
   777 # if defined ( _STLP_USE_WRAPPER_FOR_ALLOC_PARAM )
   778 # include <stl/wrappers/_slist.h>
   779 # endif
   780 
   781 #endif /* _STLP_INTERNAL_SLIST_H */
   782 
   783 // Local Variables:
   784 // mode:C++
   785 // End:
   786