/home/ntakagi/work/STLport-5.1.5/stlport/stl/_list.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Copyright (c) 1996,1997
00007  * Silicon Graphics Computer Systems, Inc.
00008  *
00009  * Copyright (c) 1997
00010  * Moscow Center for SPARC Technology
00011  *
00012  * Copyright (c) 1999
00013  * Boris Fomitchev
00014  *
00015  * This material is provided "as is", with absolutely no warranty expressed
00016  * or implied. Any use is at your own risk.
00017  *
00018  * Permission to use or copy this software for any purpose is hereby granted
00019  * without fee, provided the above notices are retained on all copies.
00020  * Permission to modify the code and to distribute modified code is granted,
00021  * provided the above notices are retained, and a notice that the code was
00022  * modified is included with the above copyright notice.
00023  *
00024  */
00025 
00026 /* NOTE: This is an internal header file, included by other STL headers.
00027  *   You should not attempt to use it directly.
00028  */
00029 
00030 #ifndef _STLP_INTERNAL_LIST_IMPL_H
00031 #define _STLP_INTERNAL_LIST_IMPL_H
00032 
00033 #ifndef _STLP_INTERNAL_ALGOBASE_H
00034 #  include <stl/_algobase.h>
00035 #endif
00036 
00037 #ifndef _STLP_INTERNAL_ALLOC_H
00038 #  include <stl/_alloc.h>
00039 #endif
00040 
00041 #ifndef _STLP_INTERNAL_ITERATOR_H
00042 #  include <stl/_iterator.h>
00043 #endif
00044 
00045 #ifndef _STLP_INTERNAL_CONSTRUCT_H
00046 #  include <stl/_construct.h>
00047 #endif
00048 
00049 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
00050 #  include <stl/_function_base.h>
00051 #endif
00052 
00053 _STLP_BEGIN_NAMESPACE
00054 
00055 _STLP_MOVE_TO_PRIV_NAMESPACE
00056 
00057 struct _List_node_base {
00058   _List_node_base* _M_next;
00059   _List_node_base* _M_prev;
00060 };
00061 
00062 template <class _Dummy>
00063 class _List_global {
00064 public:
00065   typedef _List_node_base _Node_base;
00066   static void  _STLP_CALL _Transfer(_Node_base* __pos,
00067                                     _Node_base* __first, _Node_base* __last);
00068 };
00069 
00070 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00071 _STLP_EXPORT_TEMPLATE_CLASS _List_global<bool>;
00072 #endif
00073 typedef _List_global<bool> _List_global_inst;
00074 
00075 template <class _Tp>
00076 class _List_node : public _List_node_base {
00077 public:
00078   _Tp _M_data;
00079   __TRIVIAL_STUFF(_List_node)
00080 };
00081 
00082 struct _List_iterator_base {
00083   typedef size_t                     size_type;
00084   typedef ptrdiff_t                  difference_type;
00085   typedef bidirectional_iterator_tag iterator_category;
00086 
00087   _List_node_base* _M_node;
00088 
00089   _List_iterator_base(_List_node_base* __x) : _M_node(__x) {}
00090 
00091   void _M_incr() { _M_node = _M_node->_M_next; }
00092   void _M_decr() { _M_node = _M_node->_M_prev; }
00093 };
00094 
00095 
00096 template<class _Tp, class _Traits>
00097 struct _List_iterator : public _List_iterator_base {
00098   typedef _Tp value_type;
00099   typedef typename _Traits::pointer    pointer;
00100   typedef typename _Traits::reference  reference;
00101 
00102   typedef _List_iterator<_Tp, _Traits>         _Self;
00103   typedef typename _Traits::_NonConstTraits    _NonConstTraits;
00104   typedef _List_iterator<_Tp, _NonConstTraits> iterator;
00105   typedef typename _Traits::_ConstTraits       _ConstTraits;
00106   typedef _List_iterator<_Tp, _ConstTraits>    const_iterator;
00107 
00108   typedef bidirectional_iterator_tag iterator_category;
00109   typedef _List_node<_Tp> _Node;
00110   typedef size_t size_type;
00111   typedef ptrdiff_t difference_type;
00112 
00113   explicit _List_iterator(_List_node_base* __x) : _List_iterator_base(__x) {}
00114   _List_iterator() : _List_iterator_base(0) {}
00115   //copy constructor for iterator and constructor from iterator for const_iterator
00116   _List_iterator(const iterator& __x) :  _List_iterator_base(__x._M_node) {}
00117 
00118   reference operator*() const { return __STATIC_CAST(_Node*, this->_M_node)->_M_data; }
00119 
00120   _STLP_DEFINE_ARROW_OPERATOR
00121 
00122   _Self& operator++() {
00123     this->_M_incr();
00124     return *this;
00125   }
00126   _Self operator++(int) {
00127     _Self __tmp = *this;
00128     this->_M_incr();
00129     return __tmp;
00130   }
00131   _Self& operator--() {
00132     this->_M_decr();
00133     return *this;
00134   }
00135   _Self operator--(int) {
00136     _Self __tmp = *this;
00137     this->_M_decr();
00138     return __tmp;
00139   }
00140   bool operator==(const_iterator __y ) const {
00141     return this->_M_node == __y._M_node;
00142   }
00143   bool operator!=(const_iterator __y ) const {
00144     return this->_M_node != __y._M_node;
00145   }
00146 };
00147 
00148 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00149 _STLP_MOVE_TO_STD_NAMESPACE
00150 template <class _Tp, class _Traits>
00151 struct __type_traits<_STLP_PRIV _List_iterator<_Tp, _Traits> > {
00152   typedef __false_type   has_trivial_default_constructor;
00153   typedef __true_type    has_trivial_copy_constructor;
00154   typedef __true_type    has_trivial_assignment_operator;
00155   typedef __true_type    has_trivial_destructor;
00156   typedef __false_type   is_POD_type;
00157 };
00158 _STLP_MOVE_TO_PRIV_NAMESPACE
00159 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
00160 
00161 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
00162 _STLP_MOVE_TO_STD_NAMESPACE
00163 template <class _Tp, class _Traits>
00164 inline _Tp* value_type(const _STLP_PRIV _List_iterator<_Tp, _Traits>&) { return 0; }
00165 inline bidirectional_iterator_tag iterator_category(const _STLP_PRIV _List_iterator_base&) { return bidirectional_iterator_tag();}
00166 inline ptrdiff_t* distance_type(const _STLP_PRIV _List_iterator_base&) { return 0; }
00167 _STLP_MOVE_TO_PRIV_NAMESPACE
00168 #endif
00169 
00170 // Base class that encapsulates details of allocators and helps
00171 // to simplify EH
00172 
00173 template <class _Tp, class _Alloc>
00174 class _List_base {
00175 protected:
00176   _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
00177   typedef _List_node_base _Node_base;
00178   typedef _List_node<_Tp> _Node;
00179   typedef _List_base<_Tp, _Alloc> _Self;
00180   typedef typename _Alloc_traits<_Node, _Alloc>::allocator_type _Node_allocator_type;
00181 public:
00182   typedef _STLP_alloc_proxy<_Node_base, _Node, _Node_allocator_type> _AllocProxy;
00183   typedef typename _Alloc_traits<_Tp, _Alloc>::allocator_type allocator_type;
00184 
00185   allocator_type get_allocator() const
00186   { return _STLP_CONVERT_ALLOCATOR((const _Node_allocator_type&)_M_node, _Tp); }
00187 
00188   _List_base(const allocator_type& __a) : _M_node(_STLP_CONVERT_ALLOCATOR(__a, _Node), _Node_base())
00189   { _M_empty_initialize(); }
00190   _List_base(__move_source<_Self> src) :
00191     _M_node(__move_source<_AllocProxy>(src.get()._M_node)) {
00192     if (src.get().empty())
00193       //We force this to empty.
00194       _M_empty_initialize();
00195     else {
00196       src.get()._M_empty_initialize();
00197       _M_node._M_data._M_prev->_M_next = _M_node._M_data._M_next->_M_prev = &_M_node._M_data;
00198     }
00199   }
00200 
00201   ~_List_base()
00202   { clear(); }
00203 
00204   void clear();
00205   bool empty() const { return _M_node._M_data._M_next == &_M_node._M_data; }
00206 
00207   void _M_empty_initialize() {
00208     _M_node._M_data._M_next = &_M_node._M_data;
00209     _M_node._M_data._M_prev = _M_node._M_data._M_next;
00210   }
00211 
00212 public:
00213   _AllocProxy _M_node;
00214 };
00215 
00216 #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
00217 #  define list _STLP_PTR_IMPL_NAME(list)
00218 #elif defined (_STLP_DEBUG)
00219 #  define list _STLP_NON_DBG_NAME(list)
00220 #else
00221 _STLP_MOVE_TO_STD_NAMESPACE
00222 #endif
00223 
00224 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
00225 class list;
00226 
00227 #if !defined (list)
00228 _STLP_MOVE_TO_PRIV_NAMESPACE
00229 #endif
00230 
00231 // helper functions to reduce code duplication
00232 template <class _Tp, class _Alloc, class _Predicate>
00233 void _S_remove_if(list<_Tp, _Alloc>& __that, _Predicate __pred);
00234 
00235 template <class _Tp, class _Alloc, class _BinaryPredicate>
00236 void _S_unique(list<_Tp, _Alloc>& __that, _BinaryPredicate __binary_pred);
00237 
00238 template <class _Tp, class _Alloc, class _StrictWeakOrdering>
00239 void _S_merge(list<_Tp, _Alloc>& __that, list<_Tp, _Alloc>& __x,
00240               _StrictWeakOrdering __comp);
00241 
00242 template <class _Tp, class _Alloc, class _StrictWeakOrdering>
00243 void _S_sort(list<_Tp, _Alloc>& __that, _StrictWeakOrdering __comp);
00244 
00245 #if !defined (list)
00246 _STLP_MOVE_TO_STD_NAMESPACE
00247 #endif
00248 
00249 template <class _Tp, class _Alloc>
00250 class list : public _STLP_PRIV _List_base<_Tp, _Alloc>
00251 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (list)
00252            , public __stlport_class<list<_Tp, _Alloc> >
00253 #endif
00254 {
00255   typedef _STLP_PRIV _List_base<_Tp, _Alloc> _Base;
00256   typedef list<_Tp, _Alloc> _Self;
00257   typedef _STLP_PRIV _List_node<_Tp> _Node;
00258   typedef _STLP_PRIV _List_node_base _Node_base;
00259 public:
00260   typedef _Tp value_type;
00261   typedef value_type* pointer;
00262   typedef const value_type* const_pointer;
00263   typedef value_type& reference;
00264   typedef const value_type& const_reference;
00265   typedef size_t size_type;
00266   typedef ptrdiff_t difference_type;
00267   _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
00268   typedef typename _Base::allocator_type allocator_type;
00269   typedef bidirectional_iterator_tag _Iterator_category;
00270 
00271 public:
00272   typedef _STLP_PRIV _List_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
00273   typedef _STLP_PRIV _List_iterator<_Tp, _Const_traits<_Tp> >    const_iterator;
00274   _STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS;
00275 
00276 protected:
00277 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
00278   _Node_base* _M_create_node(const_reference __x = value_type()) {
00279 #else
00280   _Node_base* _M_create_node(const_reference __x) {
00281 #endif 
00282     _Node* __p = this->_M_node.allocate(1);
00283     _STLP_TRY {
00284       _Copy_Construct(&__p->_M_data, __x);
00285     }
00286     _STLP_UNWIND(this->_M_node.deallocate(__p, 1))
00287     return __p;
00288   }
00289 
00290 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
00291   _Node_base* _M_create_node() {
00292     _Node* __p = this->_M_node.allocate(1);
00293     _STLP_TRY {
00294       _STLP_STD::_Construct(&__p->_M_data);
00295     }
00296     _STLP_UNWIND(this->_M_node.deallocate(__p, 1))
00297     return __p;
00298   }
00299 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00300 
00301 public:
00302 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
00303   explicit list(size_type __n, const_reference __val = _STLP_DEFAULT_CONSTRUCTED(value_type),
00304                 const allocator_type& __a = allocator_type())
00305 #else
00306   explicit list(size_type __n)
00307     : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type())
00308     { this->insert(begin(), __n, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
00309   list(size_type __n, const_reference __val)
00310     : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type())
00311     { this->insert(begin(), __n, __val); }
00312   list(size_type __n, const_reference __val, const allocator_type& __a)
00313 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00314     : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
00315     { this->insert(begin(), __n, __val); }
00316 
00317 #if defined (_STLP_MEMBER_TEMPLATES)
00318   // We don't need any dispatching tricks here, because insert does all of
00319   // that anyway.
00320   template <class _InputIterator>
00321   list(_InputIterator __first, _InputIterator __last,
00322        const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00323     : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
00324   { _M_insert(begin(), __first, __last); }
00325 
00326 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
00327   template <class _InputIterator>
00328   list(_InputIterator __first, _InputIterator __last)
00329     : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type())
00330   { _M_insert(begin(), __first, __last); }
00331 #  endif
00332 #else /* _STLP_MEMBER_TEMPLATES */
00333   list(const value_type* __first, const value_type* __last,
00334        const allocator_type& __a = allocator_type())
00335     : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
00336     { _M_insert(begin(), __first, __last); }
00337   list(const_iterator __first, const_iterator __last,
00338        const allocator_type& __a = allocator_type())
00339     : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
00340     { _M_insert(begin(), __first, __last); }
00341 #endif /* _STLP_MEMBER_TEMPLATES */
00342 
00343 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
00344   explicit list(const allocator_type& __a = allocator_type())
00345 #else
00346   list()
00347     : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type()) {}
00348   list(const allocator_type& __a)
00349 #endif
00350     : _STLP_PRIV _List_base<_Tp, _Alloc>(__a) {}
00351 
00352   list(const _Self& __x) : _STLP_PRIV _List_base<_Tp, _Alloc>(__x.get_allocator())
00353   { _M_insert(begin(), __x.begin(), __x.end()); }
00354 
00355   list(__move_source<_Self> src)
00356     : _STLP_PRIV _List_base<_Tp, _Alloc>(__move_source<_Base>(src.get())) {}
00357 
00358   ~list() {}
00359 
00360   _Self& operator = (const _Self& __x);
00361 
00362   iterator begin()                      { return iterator(this->_M_node._M_data._M_next); }
00363   const_iterator begin() const          { return const_iterator(this->_M_node._M_data._M_next); }
00364 
00365   iterator end()                        { return iterator(&this->_M_node._M_data); }
00366   const_iterator end() const            { return const_iterator(__CONST_CAST(_Node_base*, &this->_M_node._M_data)); }
00367 
00368   reverse_iterator rbegin()             { return reverse_iterator(end()); }
00369   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
00370 
00371   reverse_iterator rend()               { return reverse_iterator(begin()); }
00372   const_reverse_iterator rend() const   { return const_reverse_iterator(begin()); }
00373 
00374   size_type size() const {
00375     size_type __result = distance(begin(), end());
00376     return __result;
00377   }
00378   size_type max_size() const { return size_type(-1); }
00379 
00380   reference front()             { return *begin(); }
00381   const_reference front() const { return *begin(); }
00382   reference back()              { return *(--end()); }
00383   const_reference back() const  { return *(--end()); }
00384 
00385 private:
00386   void _M_swap_aux(_Self& __x) {
00387     __x._M_node._M_swap_alloc(this->_M_node);
00388     __x._M_node._M_data._M_next = this->_M_node._M_data._M_next;
00389     __x._M_node._M_data._M_next->_M_prev = &__x._M_node._M_data;
00390     __x._M_node._M_data._M_prev = this->_M_node._M_data._M_prev;
00391     __x._M_node._M_data._M_prev->_M_next = &__x._M_node._M_data;
00392     this->_M_empty_initialize();
00393   }
00394 
00395 public:
00396   void swap(_Self& __x) {
00397     if (__x.empty()) {
00398       if (this->empty()) {
00399         return;
00400       }
00401       this->_M_swap_aux(__x);
00402     } else if (this->empty()) {
00403       __x._M_swap_aux(*this);
00404     } else {
00405       this->_M_node.swap(__x._M_node);
00406       _STLP_STD::swap(this->_M_node._M_data._M_prev->_M_next, __x._M_node._M_data._M_prev->_M_next);
00407       _STLP_STD::swap(this->_M_node._M_data._M_next->_M_prev, __x._M_node._M_data._M_next->_M_prev);
00408     }
00409   }
00410 
00411 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
00412   iterator insert(iterator __pos, const_reference __x = value_type()) {
00413 #else
00414   iterator insert(iterator __pos, const_reference __x) {
00415 #endif 
00416     _Node_base* __tmp = _M_create_node(__x);
00417     _Node_base* __n = __pos._M_node;
00418     _Node_base* __p = __n->_M_prev;
00419     __tmp->_M_next = __n;
00420     __tmp->_M_prev = __p;
00421     __p->_M_next = __tmp;
00422     __n->_M_prev = __tmp;
00423     return iterator(__tmp);
00424   }
00425 
00426 private:
00427 #if defined (_STLP_MEMBER_TEMPLATES)
00428   template <class _InputIterator>
00429   void _M_insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
00430     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
00431     _M_insert_dispatch(__pos, __first, __last, _Integral());
00432   }
00433 
00434   // Check whether it's an integral type.  If so, it's not an iterator.
00435   template<class _Integer>
00436   void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
00437                           const __true_type& /*_IsIntegral*/) {
00438     _M_fill_insert(__pos, __n, __x);
00439   }
00440   template <class _InputIter>
00441   void _M_insert_dispatch(iterator __pos,
00442                           _InputIter __first, _InputIter __last,
00443                           const __false_type& /*_IsIntegral*/) {
00444 #else /* _STLP_MEMBER_TEMPLATES */
00445   void _M_insert(iterator __pos, const value_type* __first, const value_type* __last) {
00446     for (; __first != __last; ++__first)
00447       insert(__pos, *__first);
00448   }
00449   void _M_insert(iterator __pos, const_iterator __first, const_iterator __last) {
00450 #endif /* _STLP_MEMBER_TEMPLATES */
00451     //We use a temporary list to avoid the auto reference troubles (infinite loop)
00452     for (; __first != __last; ++__first)
00453       insert(__pos, *__first);
00454   }
00455 
00456 public:
00457 #if defined (_STLP_MEMBER_TEMPLATES)
00458   template <class _InputIterator>
00459   void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
00460     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
00461     _M_splice_insert_dispatch(__pos, __first, __last, _Integral());
00462   }
00463 
00464 private:
00465   // Check whether it's an integral type.  If so, it's not an iterator.
00466   template<class _Integer>
00467   void _M_splice_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
00468                           const __true_type& /*_IsIntegral*/) {
00469     _M_fill_insert(__pos, __n, __x);
00470   }
00471   template <class _InputIter>
00472   void _M_splice_insert_dispatch(iterator __pos,
00473                           _InputIter __first, _InputIter __last,
00474                           const __false_type& /*_IsIntegral*/) {
00475 #else /* _STLP_MEMBER_TEMPLATES */
00476   void insert(iterator __pos, const value_type* __first, const value_type* __last) {
00477     _Self __tmp(__first, __last, this->get_allocator());
00478     splice(__pos, __tmp);
00479   }
00480   void insert(iterator __pos, const_iterator __first, const_iterator __last) {
00481 #endif /* _STLP_MEMBER_TEMPLATES */
00482     //We use a temporary list to avoid the auto reference troubles (infinite loop)
00483     _Self __tmp(__first, __last, this->get_allocator());
00484     splice(__pos, __tmp);
00485   }
00486 
00487 public:
00488   void insert(iterator __pos, size_type __n, const_reference __x)
00489   { _M_fill_insert(__pos, __n, __x); }
00490 
00491 private:
00492   void _M_fill_insert(iterator __pos, size_type __n, const_reference __x) {
00493     for ( ; __n > 0; --__n)
00494       insert(__pos, __x);
00495   }
00496 
00497 public:
00498   void push_front(const_reference __x) { insert(begin(), __x); }
00499   void push_back (const_reference __x) { insert(end(), __x); }
00500 
00501 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00502   iterator insert(iterator __pos)
00503   { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
00504   void push_front() {insert(begin());}
00505   void push_back() {insert(end());}
00506 # endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
00507 
00508   iterator erase(iterator __pos) {
00509     _Node_base* __next_node = __pos._M_node->_M_next;
00510     _Node_base* __prev_node = __pos._M_node->_M_prev;
00511     _Node* __n = __STATIC_CAST(_Node*, __pos._M_node);
00512     __prev_node->_M_next = __next_node;
00513     __next_node->_M_prev = __prev_node;
00514     _STLP_STD::_Destroy(&__n->_M_data);
00515     this->_M_node.deallocate(__n, 1);
00516     return iterator(__next_node);
00517   }
00518 
00519   iterator erase(iterator __first, iterator __last) {
00520     while (__first != __last)
00521       erase(__first++);
00522     return __last;
00523   }
00524 
00525 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
00526   void resize(size_type __new_size, const_reference __x = value_type());
00527 #else
00528   void resize(size_type __new_size, const_reference __x);
00529   void resize(size_type __new_size)
00530   { this->resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
00531 #endif 
00533   void pop_front() { erase(begin()); }
00534   void pop_back() {
00535     iterator __tmp = end();
00536     erase(--__tmp);
00537   }
00538 
00539 public:
00540   // assign(), a generalized assignment member function.  Two
00541   // versions: one that takes a count, and one that takes a range.
00542   // The range version is a member template, so we dispatch on whether
00543   // or not the type is an integer.
00544 
00545   void assign(size_type __n, const_reference __val) { _M_fill_assign(__n, __val); }
00546 
00547   void _M_fill_assign(size_type __n, const_reference __val);
00548 
00549 #if defined (_STLP_MEMBER_TEMPLATES)
00550   template <class _InputIterator>
00551   void assign(_InputIterator __first, _InputIterator __last) {
00552     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
00553     _M_assign_dispatch(__first, __last, _Integral());
00554   }
00555 
00556   template <class _Integer>
00557   void _M_assign_dispatch(_Integer __n, _Integer __val,
00558                           const __true_type& /*_IsIntegral*/) {
00559     _M_fill_assign(__n, __val);
00560   }
00561 
00562   template <class _InputIterator>
00563   void _M_assign_dispatch(_InputIterator __first2, _InputIterator __last2,
00564                           const __false_type& /*_IsIntegral*/) {
00565 #else
00566   void assign(const value_type *__first2, const value_type *__last2) {
00567     iterator __first1 = begin();
00568     iterator __last1 = end();
00569     for ( ; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
00570       *__first1 = *__first2;
00571     if (__first2 == __last2)
00572       erase(__first1, __last1);
00573     else
00574       insert(__last1, __first2, __last2);
00575   }
00576   void assign(const_iterator __first2, const_iterator __last2) {
00577 #endif /* _STLP_MEMBER_TEMPLATES */
00578     iterator __first1 = begin();
00579     iterator __last1 = end();
00580     for ( ; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
00581       *__first1 = *__first2;
00582     if (__first2 == __last2)
00583       erase(__first1, __last1);
00584     else
00585       insert(__last1, __first2, __last2);
00586   }
00587 
00588 public:
00589   void splice(iterator __pos, _Self& __x) {
00590     if (!__x.empty()) {
00591       if (this->get_allocator() == __x.get_allocator()) {
00592         _STLP_PRIV _List_global_inst::_Transfer(__pos._M_node, __x.begin()._M_node, __x.end()._M_node);
00593       }
00594       else {
00595         insert(__pos, __x.begin(), __x.end());
00596         __x.clear();
00597       }
00598     }
00599   }
00600   void splice(iterator __pos, _Self& __x, iterator __i) {
00601     iterator __j = __i;
00602     ++__j;
00603     if (__pos == __i || __pos == __j) return;
00604     if (this->get_allocator() == __x.get_allocator()) {
00605       _STLP_PRIV _List_global_inst::_Transfer(__pos._M_node, __i._M_node, __j._M_node);
00606     }
00607     else {
00608       insert(__pos, *__i);
00609       __x.erase(__i);
00610     }
00611   }
00612   void splice(iterator __pos, _Self& __x, iterator __first, iterator __last) {
00613     if (__first != __last) {
00614       if (this->get_allocator() == __x.get_allocator()) {
00615         _STLP_PRIV _List_global_inst::_Transfer(__pos._M_node, __first._M_node, __last._M_node);
00616       }
00617       else {
00618         insert(__pos, __first, __last);
00619         __x.erase(__first, __last);
00620       }
00621     }
00622   }
00623 
00624   void remove(const_reference __val) {
00625     iterator __first = begin();
00626     iterator __last = end();
00627     while (__first != __last) {
00628       iterator __next = __first;
00629       ++__next;
00630       if (__val == *__first) erase(__first);
00631       __first = __next;
00632     }
00633   }
00634 
00635   void unique()
00636   { _STLP_PRIV _S_unique(*this, equal_to<value_type>()); }
00637 
00638   void merge(_Self& __x)
00639   { _STLP_PRIV _S_merge(*this, __x, less<value_type>()); }
00640 
00641   void reverse() {
00642     _Node_base* __p = &this->_M_node._M_data;
00643     _Node_base* __tmp = __p;
00644     do {
00645       _STLP_STD::swap(__tmp->_M_next, __tmp->_M_prev);
00646       __tmp = __tmp->_M_prev;     // Old next node is now prev.
00647     } while (__tmp != __p);
00648   }
00649 
00650   void sort()
00651   { _STLP_PRIV _S_sort(*this, less<value_type>()); }
00652 
00653 #if defined (_STLP_MEMBER_TEMPLATES)
00654   template <class _Predicate>
00655   void remove_if(_Predicate __pred)
00656   { _STLP_PRIV _S_remove_if(*this, __pred); }
00657   template <class _BinaryPredicate>
00658   void unique(_BinaryPredicate __binary_pred)
00659   { _STLP_PRIV _S_unique(*this, __binary_pred); }
00660 
00661   template <class _StrictWeakOrdering>
00662   void merge(_Self& __x,
00663              _StrictWeakOrdering __comp) {
00664     _STLP_PRIV _S_merge(*this, __x, __comp);
00665   }
00666 
00667   template <class _StrictWeakOrdering>
00668   void sort(_StrictWeakOrdering __comp)
00669   { _STLP_PRIV _S_sort(*this, __comp); }
00670 #endif /* _STLP_MEMBER_TEMPLATES */
00671 };
00672 
00673 #if defined (list)
00674 #  undef list
00675 _STLP_MOVE_TO_STD_NAMESPACE
00676 #endif
00677 
00678 _STLP_END_NAMESPACE
00679 
00680 #if !defined (_STLP_LINK_TIME_INSTANTIATION)
00681 #  include <stl/_list.c>
00682 #endif
00683 
00684 #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
00685 #  include <stl/pointers/_list.h>
00686 #endif
00687 
00688 #if defined (_STLP_DEBUG)
00689 #  include <stl/debug/_list.h>
00690 #endif
00691 
00692 _STLP_BEGIN_NAMESPACE
00693 
00694 template <class _Tp, class _Alloc>
00695 _STLP_INLINE_LOOP bool  _STLP_CALL
00696 operator==(const list<_Tp,_Alloc>& __x, const list<_Tp,_Alloc>& __y) {
00697   typedef typename list<_Tp,_Alloc>::const_iterator const_iterator;
00698   const_iterator __end1 = __x.end();
00699   const_iterator __end2 = __y.end();
00700 
00701   const_iterator __i1 = __x.begin();
00702   const_iterator __i2 = __y.begin();
00703   while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) {
00704     ++__i1;
00705     ++__i2;
00706   }
00707   return __i1 == __end1 && __i2 == __end2;
00708 }
00709 
00710 #define _STLP_EQUAL_OPERATOR_SPECIALIZED
00711 #define _STLP_TEMPLATE_HEADER    template <class _Tp, class _Alloc>
00712 #define _STLP_TEMPLATE_CONTAINER list<_Tp, _Alloc>
00713 #include <stl/_relops_cont.h>
00714 #undef _STLP_TEMPLATE_CONTAINER
00715 #undef _STLP_TEMPLATE_HEADER
00716 #undef _STLP_EQUAL_OPERATOR_SPECIALIZED
00717 
00718 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00719 template <class _Tp, class _Alloc>
00720 struct __move_traits<list<_Tp, _Alloc> > {
00721   typedef __stlp_movable implemented;
00722   typedef typename __move_traits<_Alloc>::complete complete;
00723 };
00724 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
00725 
00726 _STLP_END_NAMESPACE
00727 
00728 #endif /* _STLP_INTERNAL_LIST_IMPL_H */
00729 
00730 // Local Variables:
00731 // mode:C++
00732 // End:



Generated on Mon Mar 10 15:32:28 2008 by  doxygen 1.5.1