libstdc++
|
00001 // List implementation -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 00004 // 2011 Free Software Foundation, Inc. 00005 // 00006 // This file is part of the GNU ISO C++ Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 3, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 00017 // Under Section 7 of GPL version 3, you are granted additional 00018 // permissions described in the GCC Runtime Library Exception, version 00019 // 3.1, as published by the Free Software Foundation. 00020 00021 // You should have received a copy of the GNU General Public License and 00022 // a copy of the GCC Runtime Library Exception along with this program; 00023 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00024 // <http://www.gnu.org/licenses/>. 00025 00026 /* 00027 * 00028 * Copyright (c) 1994 00029 * Hewlett-Packard Company 00030 * 00031 * Permission to use, copy, modify, distribute and sell this software 00032 * and its documentation for any purpose is hereby granted without fee, 00033 * provided that the above copyright notice appear in all copies and 00034 * that both that copyright notice and this permission notice appear 00035 * in supporting documentation. Hewlett-Packard Company makes no 00036 * representations about the suitability of this software for any 00037 * purpose. It is provided "as is" without express or implied warranty. 00038 * 00039 * 00040 * Copyright (c) 1996,1997 00041 * Silicon Graphics Computer Systems, Inc. 00042 * 00043 * Permission to use, copy, modify, distribute and sell this software 00044 * and its documentation for any purpose is hereby granted without fee, 00045 * provided that the above copyright notice appear in all copies and 00046 * that both that copyright notice and this permission notice appear 00047 * in supporting documentation. Silicon Graphics makes no 00048 * representations about the suitability of this software for any 00049 * purpose. It is provided "as is" without express or implied warranty. 00050 */ 00051 00052 /** @file bits/stl_list.h 00053 * This is an internal header file, included by other library headers. 00054 * Do not attempt to use it directly. @headername{list} 00055 */ 00056 00057 #ifndef _STL_LIST_H 00058 #define _STL_LIST_H 1 00059 00060 #include <bits/concept_check.h> 00061 #include <initializer_list> 00062 00063 namespace std _GLIBCXX_VISIBILITY(default) 00064 { 00065 namespace __detail 00066 { 00067 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00068 00069 // Supporting structures are split into common and templated 00070 // types; the latter publicly inherits from the former in an 00071 // effort to reduce code duplication. This results in some 00072 // "needless" static_cast'ing later on, but it's all safe 00073 // downcasting. 00074 00075 /// Common part of a node in the %list. 00076 struct _List_node_base 00077 { 00078 _List_node_base* _M_next; 00079 _List_node_base* _M_prev; 00080 00081 static void 00082 swap(_List_node_base& __x, _List_node_base& __y) throw (); 00083 00084 void 00085 _M_transfer(_List_node_base* const __first, 00086 _List_node_base* const __last) throw (); 00087 00088 void 00089 _M_reverse() throw (); 00090 00091 void 00092 _M_hook(_List_node_base* const __position) throw (); 00093 00094 void 00095 _M_unhook() throw (); 00096 }; 00097 00098 _GLIBCXX_END_NAMESPACE_VERSION 00099 } // namespace detail 00100 00101 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER 00102 00103 /// An actual node in the %list. 00104 template<typename _Tp> 00105 struct _List_node : public __detail::_List_node_base 00106 { 00107 ///< User's data. 00108 _Tp _M_data; 00109 00110 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00111 template<typename... _Args> 00112 _List_node(_Args&&... __args) 00113 : __detail::_List_node_base(), _M_data(std::forward<_Args>(__args)...) 00114 { } 00115 #endif 00116 }; 00117 00118 /** 00119 * @brief A list::iterator. 00120 * 00121 * All the functions are op overloads. 00122 */ 00123 template<typename _Tp> 00124 struct _List_iterator 00125 { 00126 typedef _List_iterator<_Tp> _Self; 00127 typedef _List_node<_Tp> _Node; 00128 00129 typedef ptrdiff_t difference_type; 00130 typedef std::bidirectional_iterator_tag iterator_category; 00131 typedef _Tp value_type; 00132 typedef _Tp* pointer; 00133 typedef _Tp& reference; 00134 00135 _List_iterator() 00136 : _M_node() { } 00137 00138 explicit 00139 _List_iterator(__detail::_List_node_base* __x) 00140 : _M_node(__x) { } 00141 00142 // Must downcast from _List_node_base to _List_node to get to _M_data. 00143 reference 00144 operator*() const 00145 { return static_cast<_Node*>(_M_node)->_M_data; } 00146 00147 pointer 00148 operator->() const 00149 { return std::__addressof(static_cast<_Node*>(_M_node)->_M_data); } 00150 00151 _Self& 00152 operator++() 00153 { 00154 _M_node = _M_node->_M_next; 00155 return *this; 00156 } 00157 00158 _Self 00159 operator++(int) 00160 { 00161 _Self __tmp = *this; 00162 _M_node = _M_node->_M_next; 00163 return __tmp; 00164 } 00165 00166 _Self& 00167 operator--() 00168 { 00169 _M_node = _M_node->_M_prev; 00170 return *this; 00171 } 00172 00173 _Self 00174 operator--(int) 00175 { 00176 _Self __tmp = *this; 00177 _M_node = _M_node->_M_prev; 00178 return __tmp; 00179 } 00180 00181 bool 00182 operator==(const _Self& __x) const 00183 { return _M_node == __x._M_node; } 00184 00185 bool 00186 operator!=(const _Self& __x) const 00187 { return _M_node != __x._M_node; } 00188 00189 // The only member points to the %list element. 00190 __detail::_List_node_base* _M_node; 00191 }; 00192 00193 /** 00194 * @brief A list::const_iterator. 00195 * 00196 * All the functions are op overloads. 00197 */ 00198 template<typename _Tp> 00199 struct _List_const_iterator 00200 { 00201 typedef _List_const_iterator<_Tp> _Self; 00202 typedef const _List_node<_Tp> _Node; 00203 typedef _List_iterator<_Tp> iterator; 00204 00205 typedef ptrdiff_t difference_type; 00206 typedef std::bidirectional_iterator_tag iterator_category; 00207 typedef _Tp value_type; 00208 typedef const _Tp* pointer; 00209 typedef const _Tp& reference; 00210 00211 _List_const_iterator() 00212 : _M_node() { } 00213 00214 explicit 00215 _List_const_iterator(const __detail::_List_node_base* __x) 00216 : _M_node(__x) { } 00217 00218 _List_const_iterator(const iterator& __x) 00219 : _M_node(__x._M_node) { } 00220 00221 // Must downcast from List_node_base to _List_node to get to 00222 // _M_data. 00223 reference 00224 operator*() const 00225 { return static_cast<_Node*>(_M_node)->_M_data; } 00226 00227 pointer 00228 operator->() const 00229 { return std::__addressof(static_cast<_Node*>(_M_node)->_M_data); } 00230 00231 _Self& 00232 operator++() 00233 { 00234 _M_node = _M_node->_M_next; 00235 return *this; 00236 } 00237 00238 _Self 00239 operator++(int) 00240 { 00241 _Self __tmp = *this; 00242 _M_node = _M_node->_M_next; 00243 return __tmp; 00244 } 00245 00246 _Self& 00247 operator--() 00248 { 00249 _M_node = _M_node->_M_prev; 00250 return *this; 00251 } 00252 00253 _Self 00254 operator--(int) 00255 { 00256 _Self __tmp = *this; 00257 _M_node = _M_node->_M_prev; 00258 return __tmp; 00259 } 00260 00261 bool 00262 operator==(const _Self& __x) const 00263 { return _M_node == __x._M_node; } 00264 00265 bool 00266 operator!=(const _Self& __x) const 00267 { return _M_node != __x._M_node; } 00268 00269 // The only member points to the %list element. 00270 const __detail::_List_node_base* _M_node; 00271 }; 00272 00273 template<typename _Val> 00274 inline bool 00275 operator==(const _List_iterator<_Val>& __x, 00276 const _List_const_iterator<_Val>& __y) 00277 { return __x._M_node == __y._M_node; } 00278 00279 template<typename _Val> 00280 inline bool 00281 operator!=(const _List_iterator<_Val>& __x, 00282 const _List_const_iterator<_Val>& __y) 00283 { return __x._M_node != __y._M_node; } 00284 00285 00286 /// See bits/stl_deque.h's _Deque_base for an explanation. 00287 template<typename _Tp, typename _Alloc> 00288 class _List_base 00289 { 00290 protected: 00291 // NOTA BENE 00292 // The stored instance is not actually of "allocator_type"'s 00293 // type. Instead we rebind the type to 00294 // Allocator<List_node<Tp>>, which according to [20.1.5]/4 00295 // should probably be the same. List_node<Tp> is not the same 00296 // size as Tp (it's two pointers larger), and specializations on 00297 // Tp may go unused because List_node<Tp> is being bound 00298 // instead. 00299 // 00300 // We put this to the test in the constructors and in 00301 // get_allocator, where we use conversions between 00302 // allocator_type and _Node_alloc_type. The conversion is 00303 // required by table 32 in [20.1.5]. 00304 typedef typename _Alloc::template rebind<_List_node<_Tp> >::other 00305 _Node_alloc_type; 00306 00307 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type; 00308 00309 struct _List_impl 00310 : public _Node_alloc_type 00311 { 00312 __detail::_List_node_base _M_node; 00313 00314 _List_impl() 00315 : _Node_alloc_type(), _M_node() 00316 { } 00317 00318 _List_impl(const _Node_alloc_type& __a) 00319 : _Node_alloc_type(__a), _M_node() 00320 { } 00321 }; 00322 00323 _List_impl _M_impl; 00324 00325 _List_node<_Tp>* 00326 _M_get_node() 00327 { return _M_impl._Node_alloc_type::allocate(1); } 00328 00329 void 00330 _M_put_node(_List_node<_Tp>* __p) 00331 { _M_impl._Node_alloc_type::deallocate(__p, 1); } 00332 00333 public: 00334 typedef _Alloc allocator_type; 00335 00336 _Node_alloc_type& 00337 _M_get_Node_allocator() 00338 { return *static_cast<_Node_alloc_type*>(&this->_M_impl); } 00339 00340 const _Node_alloc_type& 00341 _M_get_Node_allocator() const 00342 { return *static_cast<const _Node_alloc_type*>(&this->_M_impl); } 00343 00344 _Tp_alloc_type 00345 _M_get_Tp_allocator() const 00346 { return _Tp_alloc_type(_M_get_Node_allocator()); } 00347 00348 allocator_type 00349 get_allocator() const 00350 { return allocator_type(_M_get_Node_allocator()); } 00351 00352 _List_base() 00353 : _M_impl() 00354 { _M_init(); } 00355 00356 _List_base(const allocator_type& __a) 00357 : _M_impl(__a) 00358 { _M_init(); } 00359 00360 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00361 _List_base(_List_base&& __x) 00362 : _M_impl(__x._M_get_Node_allocator()) 00363 { 00364 _M_init(); 00365 __detail::_List_node_base::swap(this->_M_impl._M_node, 00366 __x._M_impl._M_node); 00367 } 00368 #endif 00369 00370 // This is what actually destroys the list. 00371 ~_List_base() 00372 { _M_clear(); } 00373 00374 void 00375 _M_clear(); 00376 00377 void 00378 _M_init() 00379 { 00380 this->_M_impl._M_node._M_next = &this->_M_impl._M_node; 00381 this->_M_impl._M_node._M_prev = &this->_M_impl._M_node; 00382 } 00383 }; 00384 00385 /** 00386 * @brief A standard container with linear time access to elements, 00387 * and fixed time insertion/deletion at any point in the sequence. 00388 * 00389 * @ingroup sequences 00390 * 00391 * Meets the requirements of a <a href="tables.html#65">container</a>, a 00392 * <a href="tables.html#66">reversible container</a>, and a 00393 * <a href="tables.html#67">sequence</a>, including the 00394 * <a href="tables.html#68">optional sequence requirements</a> with the 00395 * %exception of @c at and @c operator[]. 00396 * 00397 * This is a @e doubly @e linked %list. Traversal up and down the 00398 * %list requires linear time, but adding and removing elements (or 00399 * @e nodes) is done in constant time, regardless of where the 00400 * change takes place. Unlike std::vector and std::deque, 00401 * random-access iterators are not provided, so subscripting ( @c 00402 * [] ) access is not allowed. For algorithms which only need 00403 * sequential access, this lack makes no difference. 00404 * 00405 * Also unlike the other standard containers, std::list provides 00406 * specialized algorithms %unique to linked lists, such as 00407 * splicing, sorting, and in-place reversal. 00408 * 00409 * A couple points on memory allocation for list<Tp>: 00410 * 00411 * First, we never actually allocate a Tp, we allocate 00412 * List_node<Tp>'s and trust [20.1.5]/4 to DTRT. This is to ensure 00413 * that after elements from %list<X,Alloc1> are spliced into 00414 * %list<X,Alloc2>, destroying the memory of the second %list is a 00415 * valid operation, i.e., Alloc1 giveth and Alloc2 taketh away. 00416 * 00417 * Second, a %list conceptually represented as 00418 * @code 00419 * A <---> B <---> C <---> D 00420 * @endcode 00421 * is actually circular; a link exists between A and D. The %list 00422 * class holds (as its only data member) a private list::iterator 00423 * pointing to @e D, not to @e A! To get to the head of the %list, 00424 * we start at the tail and move forward by one. When this member 00425 * iterator's next/previous pointers refer to itself, the %list is 00426 * %empty. 00427 */ 00428 template<typename _Tp, typename _Alloc = std::allocator<_Tp> > 00429 class list : protected _List_base<_Tp, _Alloc> 00430 { 00431 // concept requirements 00432 typedef typename _Alloc::value_type _Alloc_value_type; 00433 __glibcxx_class_requires(_Tp, _SGIAssignableConcept) 00434 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept) 00435 00436 typedef _List_base<_Tp, _Alloc> _Base; 00437 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; 00438 00439 public: 00440 typedef _Tp value_type; 00441 typedef typename _Tp_alloc_type::pointer pointer; 00442 typedef typename _Tp_alloc_type::const_pointer const_pointer; 00443 typedef typename _Tp_alloc_type::reference reference; 00444 typedef typename _Tp_alloc_type::const_reference const_reference; 00445 typedef _List_iterator<_Tp> iterator; 00446 typedef _List_const_iterator<_Tp> const_iterator; 00447 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00448 typedef std::reverse_iterator<iterator> reverse_iterator; 00449 typedef size_t size_type; 00450 typedef ptrdiff_t difference_type; 00451 typedef _Alloc allocator_type; 00452 00453 protected: 00454 // Note that pointers-to-_Node's can be ctor-converted to 00455 // iterator types. 00456 typedef _List_node<_Tp> _Node; 00457 00458 using _Base::_M_impl; 00459 using _Base::_M_put_node; 00460 using _Base::_M_get_node; 00461 using _Base::_M_get_Tp_allocator; 00462 using _Base::_M_get_Node_allocator; 00463 00464 /** 00465 * @param x An instance of user data. 00466 * 00467 * Allocates space for a new node and constructs a copy of @a x in it. 00468 */ 00469 #ifndef __GXX_EXPERIMENTAL_CXX0X__ 00470 _Node* 00471 _M_create_node(const value_type& __x) 00472 { 00473 _Node* __p = this->_M_get_node(); 00474 __try 00475 { 00476 _M_get_Tp_allocator().construct 00477 (std::__addressof(__p->_M_data), __x); 00478 } 00479 __catch(...) 00480 { 00481 _M_put_node(__p); 00482 __throw_exception_again; 00483 } 00484 return __p; 00485 } 00486 #else 00487 template<typename... _Args> 00488 _Node* 00489 _M_create_node(_Args&&... __args) 00490 { 00491 _Node* __p = this->_M_get_node(); 00492 __try 00493 { 00494 _M_get_Node_allocator().construct(__p, 00495 std::forward<_Args>(__args)...); 00496 } 00497 __catch(...) 00498 { 00499 _M_put_node(__p); 00500 __throw_exception_again; 00501 } 00502 return __p; 00503 } 00504 #endif 00505 00506 public: 00507 // [23.2.2.1] construct/copy/destroy 00508 // (assign() and get_allocator() are also listed in this section) 00509 /** 00510 * @brief Default constructor creates no elements. 00511 */ 00512 list() 00513 : _Base() { } 00514 00515 /** 00516 * @brief Creates a %list with no elements. 00517 * @param a An allocator object. 00518 */ 00519 explicit 00520 list(const allocator_type& __a) 00521 : _Base(__a) { } 00522 00523 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00524 /** 00525 * @brief Creates a %list with default constructed elements. 00526 * @param n The number of elements to initially create. 00527 * 00528 * This constructor fills the %list with @a n default 00529 * constructed elements. 00530 */ 00531 explicit 00532 list(size_type __n) 00533 : _Base() 00534 { _M_default_initialize(__n); } 00535 00536 /** 00537 * @brief Creates a %list with copies of an exemplar element. 00538 * @param n The number of elements to initially create. 00539 * @param value An element to copy. 00540 * @param a An allocator object. 00541 * 00542 * This constructor fills the %list with @a n copies of @a value. 00543 */ 00544 list(size_type __n, const value_type& __value, 00545 const allocator_type& __a = allocator_type()) 00546 : _Base(__a) 00547 { _M_fill_initialize(__n, __value); } 00548 #else 00549 /** 00550 * @brief Creates a %list with copies of an exemplar element. 00551 * @param n The number of elements to initially create. 00552 * @param value An element to copy. 00553 * @param a An allocator object. 00554 * 00555 * This constructor fills the %list with @a n copies of @a value. 00556 */ 00557 explicit 00558 list(size_type __n, const value_type& __value = value_type(), 00559 const allocator_type& __a = allocator_type()) 00560 : _Base(__a) 00561 { _M_fill_initialize(__n, __value); } 00562 #endif 00563 00564 /** 00565 * @brief %List copy constructor. 00566 * @param x A %list of identical element and allocator types. 00567 * 00568 * The newly-created %list uses a copy of the allocation object used 00569 * by @a x. 00570 */ 00571 list(const list& __x) 00572 : _Base(__x._M_get_Node_allocator()) 00573 { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); } 00574 00575 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00576 /** 00577 * @brief %List move constructor. 00578 * @param x A %list of identical element and allocator types. 00579 * 00580 * The newly-created %list contains the exact contents of @a x. 00581 * The contents of @a x are a valid, but unspecified %list. 00582 */ 00583 list(list&& __x) 00584 : _Base(std::move(__x)) { } 00585 00586 /** 00587 * @brief Builds a %list from an initializer_list 00588 * @param l An initializer_list of value_type. 00589 * @param a An allocator object. 00590 * 00591 * Create a %list consisting of copies of the elements in the 00592 * initializer_list @a l. This is linear in l.size(). 00593 */ 00594 list(initializer_list<value_type> __l, 00595 const allocator_type& __a = allocator_type()) 00596 : _Base(__a) 00597 { _M_initialize_dispatch(__l.begin(), __l.end(), __false_type()); } 00598 #endif 00599 00600 /** 00601 * @brief Builds a %list from a range. 00602 * @param first An input iterator. 00603 * @param last An input iterator. 00604 * @param a An allocator object. 00605 * 00606 * Create a %list consisting of copies of the elements from 00607 * [@a first,@a last). This is linear in N (where N is 00608 * distance(@a first,@a last)). 00609 */ 00610 template<typename _InputIterator> 00611 list(_InputIterator __first, _InputIterator __last, 00612 const allocator_type& __a = allocator_type()) 00613 : _Base(__a) 00614 { 00615 // Check whether it's an integral type. If so, it's not an iterator. 00616 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 00617 _M_initialize_dispatch(__first, __last, _Integral()); 00618 } 00619 00620 /** 00621 * No explicit dtor needed as the _Base dtor takes care of 00622 * things. The _Base dtor only erases the elements, and note 00623 * that if the elements themselves are pointers, the pointed-to 00624 * memory is not touched in any way. Managing the pointer is 00625 * the user's responsibility. 00626 */ 00627 00628 /** 00629 * @brief %List assignment operator. 00630 * @param x A %list of identical element and allocator types. 00631 * 00632 * All the elements of @a x are copied, but unlike the copy 00633 * constructor, the allocator object is not copied. 00634 */ 00635 list& 00636 operator=(const list& __x); 00637 00638 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00639 /** 00640 * @brief %List move assignment operator. 00641 * @param x A %list of identical element and allocator types. 00642 * 00643 * The contents of @a x are moved into this %list (without copying). 00644 * @a x is a valid, but unspecified %list 00645 */ 00646 list& 00647 operator=(list&& __x) 00648 { 00649 // NB: DR 1204. 00650 // NB: DR 675. 00651 this->clear(); 00652 this->swap(__x); 00653 return *this; 00654 } 00655 00656 /** 00657 * @brief %List initializer list assignment operator. 00658 * @param l An initializer_list of value_type. 00659 * 00660 * Replace the contents of the %list with copies of the elements 00661 * in the initializer_list @a l. This is linear in l.size(). 00662 */ 00663 list& 00664 operator=(initializer_list<value_type> __l) 00665 { 00666 this->assign(__l.begin(), __l.end()); 00667 return *this; 00668 } 00669 #endif 00670 00671 /** 00672 * @brief Assigns a given value to a %list. 00673 * @param n Number of elements to be assigned. 00674 * @param val Value to be assigned. 00675 * 00676 * This function fills a %list with @a n copies of the given 00677 * value. Note that the assignment completely changes the %list 00678 * and that the resulting %list's size is the same as the number 00679 * of elements assigned. Old data may be lost. 00680 */ 00681 void 00682 assign(size_type __n, const value_type& __val) 00683 { _M_fill_assign(__n, __val); } 00684 00685 /** 00686 * @brief Assigns a range to a %list. 00687 * @param first An input iterator. 00688 * @param last An input iterator. 00689 * 00690 * This function fills a %list with copies of the elements in the 00691 * range [@a first,@a last). 00692 * 00693 * Note that the assignment completely changes the %list and 00694 * that the resulting %list's size is the same as the number of 00695 * elements assigned. Old data may be lost. 00696 */ 00697 template<typename _InputIterator> 00698 void 00699 assign(_InputIterator __first, _InputIterator __last) 00700 { 00701 // Check whether it's an integral type. If so, it's not an iterator. 00702 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 00703 _M_assign_dispatch(__first, __last, _Integral()); 00704 } 00705 00706 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00707 /** 00708 * @brief Assigns an initializer_list to a %list. 00709 * @param l An initializer_list of value_type. 00710 * 00711 * Replace the contents of the %list with copies of the elements 00712 * in the initializer_list @a l. This is linear in l.size(). 00713 */ 00714 void 00715 assign(initializer_list<value_type> __l) 00716 { this->assign(__l.begin(), __l.end()); } 00717 #endif 00718 00719 /// Get a copy of the memory allocation object. 00720 allocator_type 00721 get_allocator() const 00722 { return _Base::get_allocator(); } 00723 00724 // iterators 00725 /** 00726 * Returns a read/write iterator that points to the first element in the 00727 * %list. Iteration is done in ordinary element order. 00728 */ 00729 iterator 00730 begin() 00731 { return iterator(this->_M_impl._M_node._M_next); } 00732 00733 /** 00734 * Returns a read-only (constant) iterator that points to the 00735 * first element in the %list. Iteration is done in ordinary 00736 * element order. 00737 */ 00738 const_iterator 00739 begin() const 00740 { return const_iterator(this->_M_impl._M_node._M_next); } 00741 00742 /** 00743 * Returns a read/write iterator that points one past the last 00744 * element in the %list. Iteration is done in ordinary element 00745 * order. 00746 */ 00747 iterator 00748 end() 00749 { return iterator(&this->_M_impl._M_node); } 00750 00751 /** 00752 * Returns a read-only (constant) iterator that points one past 00753 * the last element in the %list. Iteration is done in ordinary 00754 * element order. 00755 */ 00756 const_iterator 00757 end() const 00758 { return const_iterator(&this->_M_impl._M_node); } 00759 00760 /** 00761 * Returns a read/write reverse iterator that points to the last 00762 * element in the %list. Iteration is done in reverse element 00763 * order. 00764 */ 00765 reverse_iterator 00766 rbegin() 00767 { return reverse_iterator(end()); } 00768 00769 /** 00770 * Returns a read-only (constant) reverse iterator that points to 00771 * the last element in the %list. Iteration is done in reverse 00772 * element order. 00773 */ 00774 const_reverse_iterator 00775 rbegin() const 00776 { return const_reverse_iterator(end()); } 00777 00778 /** 00779 * Returns a read/write reverse iterator that points to one 00780 * before the first element in the %list. Iteration is done in 00781 * reverse element order. 00782 */ 00783 reverse_iterator 00784 rend() 00785 { return reverse_iterator(begin()); } 00786 00787 /** 00788 * Returns a read-only (constant) reverse iterator that points to one 00789 * before the first element in the %list. Iteration is done in reverse 00790 * element order. 00791 */ 00792 const_reverse_iterator 00793 rend() const 00794 { return const_reverse_iterator(begin()); } 00795 00796 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00797 /** 00798 * Returns a read-only (constant) iterator that points to the 00799 * first element in the %list. Iteration is done in ordinary 00800 * element order. 00801 */ 00802 const_iterator 00803 cbegin() const 00804 { return const_iterator(this->_M_impl._M_node._M_next); } 00805 00806 /** 00807 * Returns a read-only (constant) iterator that points one past 00808 * the last element in the %list. Iteration is done in ordinary 00809 * element order. 00810 */ 00811 const_iterator 00812 cend() const 00813 { return const_iterator(&this->_M_impl._M_node); } 00814 00815 /** 00816 * Returns a read-only (constant) reverse iterator that points to 00817 * the last element in the %list. Iteration is done in reverse 00818 * element order. 00819 */ 00820 const_reverse_iterator 00821 crbegin() const 00822 { return const_reverse_iterator(end()); } 00823 00824 /** 00825 * Returns a read-only (constant) reverse iterator that points to one 00826 * before the first element in the %list. Iteration is done in reverse 00827 * element order. 00828 */ 00829 const_reverse_iterator 00830 crend() const 00831 { return const_reverse_iterator(begin()); } 00832 #endif 00833 00834 // [23.2.2.2] capacity 00835 /** 00836 * Returns true if the %list is empty. (Thus begin() would equal 00837 * end().) 00838 */ 00839 bool 00840 empty() const 00841 { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; } 00842 00843 /** Returns the number of elements in the %list. */ 00844 size_type 00845 size() const 00846 { return std::distance(begin(), end()); } 00847 00848 /** Returns the size() of the largest possible %list. */ 00849 size_type 00850 max_size() const 00851 { return _M_get_Node_allocator().max_size(); } 00852 00853 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00854 /** 00855 * @brief Resizes the %list to the specified number of elements. 00856 * @param new_size Number of elements the %list should contain. 00857 * 00858 * This function will %resize the %list to the specified number 00859 * of elements. If the number is smaller than the %list's 00860 * current size the %list is truncated, otherwise default 00861 * constructed elements are appended. 00862 */ 00863 void 00864 resize(size_type __new_size); 00865 00866 /** 00867 * @brief Resizes the %list to the specified number of elements. 00868 * @param new_size Number of elements the %list should contain. 00869 * @param x Data with which new elements should be populated. 00870 * 00871 * This function will %resize the %list to the specified number 00872 * of elements. If the number is smaller than the %list's 00873 * current size the %list is truncated, otherwise the %list is 00874 * extended and new elements are populated with given data. 00875 */ 00876 void 00877 resize(size_type __new_size, const value_type& __x); 00878 #else 00879 /** 00880 * @brief Resizes the %list to the specified number of elements. 00881 * @param new_size Number of elements the %list should contain. 00882 * @param x Data with which new elements should be populated. 00883 * 00884 * This function will %resize the %list to the specified number 00885 * of elements. If the number is smaller than the %list's 00886 * current size the %list is truncated, otherwise the %list is 00887 * extended and new elements are populated with given data. 00888 */ 00889 void 00890 resize(size_type __new_size, value_type __x = value_type()); 00891 #endif 00892 00893 // element access 00894 /** 00895 * Returns a read/write reference to the data at the first 00896 * element of the %list. 00897 */ 00898 reference 00899 front() 00900 { return *begin(); } 00901 00902 /** 00903 * Returns a read-only (constant) reference to the data at the first 00904 * element of the %list. 00905 */ 00906 const_reference 00907 front() const 00908 { return *begin(); } 00909 00910 /** 00911 * Returns a read/write reference to the data at the last element 00912 * of the %list. 00913 */ 00914 reference 00915 back() 00916 { 00917 iterator __tmp = end(); 00918 --__tmp; 00919 return *__tmp; 00920 } 00921 00922 /** 00923 * Returns a read-only (constant) reference to the data at the last 00924 * element of the %list. 00925 */ 00926 const_reference 00927 back() const 00928 { 00929 const_iterator __tmp = end(); 00930 --__tmp; 00931 return *__tmp; 00932 } 00933 00934 // [23.2.2.3] modifiers 00935 /** 00936 * @brief Add data to the front of the %list. 00937 * @param x Data to be added. 00938 * 00939 * This is a typical stack operation. The function creates an 00940 * element at the front of the %list and assigns the given data 00941 * to it. Due to the nature of a %list this operation can be 00942 * done in constant time, and does not invalidate iterators and 00943 * references. 00944 */ 00945 void 00946 push_front(const value_type& __x) 00947 { this->_M_insert(begin(), __x); } 00948 00949 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00950 void 00951 push_front(value_type&& __x) 00952 { this->_M_insert(begin(), std::move(__x)); } 00953 00954 template<typename... _Args> 00955 void 00956 emplace_front(_Args&&... __args) 00957 { this->_M_insert(begin(), std::forward<_Args>(__args)...); } 00958 #endif 00959 00960 /** 00961 * @brief Removes first element. 00962 * 00963 * This is a typical stack operation. It shrinks the %list by 00964 * one. Due to the nature of a %list this operation can be done 00965 * in constant time, and only invalidates iterators/references to 00966 * the element being removed. 00967 * 00968 * Note that no data is returned, and if the first element's data 00969 * is needed, it should be retrieved before pop_front() is 00970 * called. 00971 */ 00972 void 00973 pop_front() 00974 { this->_M_erase(begin()); } 00975 00976 /** 00977 * @brief Add data to the end of the %list. 00978 * @param x Data to be added. 00979 * 00980 * This is a typical stack operation. The function creates an 00981 * element at the end of the %list and assigns the given data to 00982 * it. Due to the nature of a %list this operation can be done 00983 * in constant time, and does not invalidate iterators and 00984 * references. 00985 */ 00986 void 00987 push_back(const value_type& __x) 00988 { this->_M_insert(end(), __x); } 00989 00990 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00991 void 00992 push_back(value_type&& __x) 00993 { this->_M_insert(end(), std::move(__x)); } 00994 00995 template<typename... _Args> 00996 void 00997 emplace_back(_Args&&... __args) 00998 { this->_M_insert(end(), std::forward<_Args>(__args)...); } 00999 #endif 01000 01001 /** 01002 * @brief Removes last element. 01003 * 01004 * This is a typical stack operation. It shrinks the %list by 01005 * one. Due to the nature of a %list this operation can be done 01006 * in constant time, and only invalidates iterators/references to 01007 * the element being removed. 01008 * 01009 * Note that no data is returned, and if the last element's data 01010 * is needed, it should be retrieved before pop_back() is called. 01011 */ 01012 void 01013 pop_back() 01014 { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); } 01015 01016 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01017 /** 01018 * @brief Constructs object in %list before specified iterator. 01019 * @param position A const_iterator into the %list. 01020 * @param args Arguments. 01021 * @return An iterator that points to the inserted data. 01022 * 01023 * This function will insert an object of type T constructed 01024 * with T(std::forward<Args>(args)...) before the specified 01025 * location. Due to the nature of a %list this operation can 01026 * be done in constant time, and does not invalidate iterators 01027 * and references. 01028 */ 01029 template<typename... _Args> 01030 iterator 01031 emplace(iterator __position, _Args&&... __args); 01032 #endif 01033 01034 /** 01035 * @brief Inserts given value into %list before specified iterator. 01036 * @param position An iterator into the %list. 01037 * @param x Data to be inserted. 01038 * @return An iterator that points to the inserted data. 01039 * 01040 * This function will insert a copy of the given value before 01041 * the specified location. Due to the nature of a %list this 01042 * operation can be done in constant time, and does not 01043 * invalidate iterators and references. 01044 */ 01045 iterator 01046 insert(iterator __position, const value_type& __x); 01047 01048 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01049 /** 01050 * @brief Inserts given rvalue into %list before specified iterator. 01051 * @param position An iterator into the %list. 01052 * @param x Data to be inserted. 01053 * @return An iterator that points to the inserted data. 01054 * 01055 * This function will insert a copy of the given rvalue before 01056 * the specified location. Due to the nature of a %list this 01057 * operation can be done in constant time, and does not 01058 * invalidate iterators and references. 01059 */ 01060 iterator 01061 insert(iterator __position, value_type&& __x) 01062 { return emplace(__position, std::move(__x)); } 01063 01064 /** 01065 * @brief Inserts the contents of an initializer_list into %list 01066 * before specified iterator. 01067 * @param p An iterator into the %list. 01068 * @param l An initializer_list of value_type. 01069 * 01070 * This function will insert copies of the data in the 01071 * initializer_list @a l into the %list before the location 01072 * specified by @a p. 01073 * 01074 * This operation is linear in the number of elements inserted and 01075 * does not invalidate iterators and references. 01076 */ 01077 void 01078 insert(iterator __p, initializer_list<value_type> __l) 01079 { this->insert(__p, __l.begin(), __l.end()); } 01080 #endif 01081 01082 /** 01083 * @brief Inserts a number of copies of given data into the %list. 01084 * @param position An iterator into the %list. 01085 * @param n Number of elements to be inserted. 01086 * @param x Data to be inserted. 01087 * 01088 * This function will insert a specified number of copies of the 01089 * given data before the location specified by @a position. 01090 * 01091 * This operation is linear in the number of elements inserted and 01092 * does not invalidate iterators and references. 01093 */ 01094 void 01095 insert(iterator __position, size_type __n, const value_type& __x) 01096 { 01097 list __tmp(__n, __x, _M_get_Node_allocator()); 01098 splice(__position, __tmp); 01099 } 01100 01101 /** 01102 * @brief Inserts a range into the %list. 01103 * @param position An iterator into the %list. 01104 * @param first An input iterator. 01105 * @param last An input iterator. 01106 * 01107 * This function will insert copies of the data in the range [@a 01108 * first,@a last) into the %list before the location specified by 01109 * @a position. 01110 * 01111 * This operation is linear in the number of elements inserted and 01112 * does not invalidate iterators and references. 01113 */ 01114 template<typename _InputIterator> 01115 void 01116 insert(iterator __position, _InputIterator __first, 01117 _InputIterator __last) 01118 { 01119 list __tmp(__first, __last, _M_get_Node_allocator()); 01120 splice(__position, __tmp); 01121 } 01122 01123 /** 01124 * @brief Remove element at given position. 01125 * @param position Iterator pointing to element to be erased. 01126 * @return An iterator pointing to the next element (or end()). 01127 * 01128 * This function will erase the element at the given position and thus 01129 * shorten the %list by one. 01130 * 01131 * Due to the nature of a %list this operation can be done in 01132 * constant time, and only invalidates iterators/references to 01133 * the element being removed. The user is also cautioned that 01134 * this function only erases the element, and that if the element 01135 * is itself a pointer, the pointed-to memory is not touched in 01136 * any way. Managing the pointer is the user's responsibility. 01137 */ 01138 iterator 01139 erase(iterator __position); 01140 01141 /** 01142 * @brief Remove a range of elements. 01143 * @param first Iterator pointing to the first element to be erased. 01144 * @param last Iterator pointing to one past the last element to be 01145 * erased. 01146 * @return An iterator pointing to the element pointed to by @a last 01147 * prior to erasing (or end()). 01148 * 01149 * This function will erase the elements in the range @a 01150 * [first,last) and shorten the %list accordingly. 01151 * 01152 * This operation is linear time in the size of the range and only 01153 * invalidates iterators/references to the element being removed. 01154 * The user is also cautioned that this function only erases the 01155 * elements, and that if the elements themselves are pointers, the 01156 * pointed-to memory is not touched in any way. Managing the pointer 01157 * is the user's responsibility. 01158 */ 01159 iterator 01160 erase(iterator __first, iterator __last) 01161 { 01162 while (__first != __last) 01163 __first = erase(__first); 01164 return __last; 01165 } 01166 01167 /** 01168 * @brief Swaps data with another %list. 01169 * @param x A %list of the same element and allocator types. 01170 * 01171 * This exchanges the elements between two lists in constant 01172 * time. Note that the global std::swap() function is 01173 * specialized such that std::swap(l1,l2) will feed to this 01174 * function. 01175 */ 01176 void 01177 swap(list& __x) 01178 { 01179 __detail::_List_node_base::swap(this->_M_impl._M_node, 01180 __x._M_impl._M_node); 01181 01182 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01183 // 431. Swapping containers with unequal allocators. 01184 std::__alloc_swap<typename _Base::_Node_alloc_type>:: 01185 _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator()); 01186 } 01187 01188 /** 01189 * Erases all the elements. Note that this function only erases 01190 * the elements, and that if the elements themselves are 01191 * pointers, the pointed-to memory is not touched in any way. 01192 * Managing the pointer is the user's responsibility. 01193 */ 01194 void 01195 clear() 01196 { 01197 _Base::_M_clear(); 01198 _Base::_M_init(); 01199 } 01200 01201 // [23.2.2.4] list operations 01202 /** 01203 * @brief Insert contents of another %list. 01204 * @param position Iterator referencing the element to insert before. 01205 * @param x Source list. 01206 * 01207 * The elements of @a x are inserted in constant time in front of 01208 * the element referenced by @a position. @a x becomes an empty 01209 * list. 01210 * 01211 * Requires this != @a x. 01212 */ 01213 void 01214 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01215 splice(iterator __position, list&& __x) 01216 #else 01217 splice(iterator __position, list& __x) 01218 #endif 01219 { 01220 if (!__x.empty()) 01221 { 01222 _M_check_equal_allocators(__x); 01223 01224 this->_M_transfer(__position, __x.begin(), __x.end()); 01225 } 01226 } 01227 01228 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01229 void 01230 splice(iterator __position, list& __x) 01231 { splice(__position, std::move(__x)); } 01232 #endif 01233 01234 /** 01235 * @brief Insert element from another %list. 01236 * @param position Iterator referencing the element to insert before. 01237 * @param x Source list. 01238 * @param i Iterator referencing the element to move. 01239 * 01240 * Removes the element in list @a x referenced by @a i and 01241 * inserts it into the current list before @a position. 01242 */ 01243 void 01244 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01245 splice(iterator __position, list&& __x, iterator __i) 01246 #else 01247 splice(iterator __position, list& __x, iterator __i) 01248 #endif 01249 { 01250 iterator __j = __i; 01251 ++__j; 01252 if (__position == __i || __position == __j) 01253 return; 01254 01255 if (this != &__x) 01256 _M_check_equal_allocators(__x); 01257 01258 this->_M_transfer(__position, __i, __j); 01259 } 01260 01261 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01262 void 01263 splice(iterator __position, list& __x, iterator __i) 01264 { splice(__position, std::move(__x), __i); } 01265 #endif 01266 01267 /** 01268 * @brief Insert range from another %list. 01269 * @param position Iterator referencing the element to insert before. 01270 * @param x Source list. 01271 * @param first Iterator referencing the start of range in x. 01272 * @param last Iterator referencing the end of range in x. 01273 * 01274 * Removes elements in the range [first,last) and inserts them 01275 * before @a position in constant time. 01276 * 01277 * Undefined if @a position is in [first,last). 01278 */ 01279 void 01280 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01281 splice(iterator __position, list&& __x, iterator __first, 01282 iterator __last) 01283 #else 01284 splice(iterator __position, list& __x, iterator __first, 01285 iterator __last) 01286 #endif 01287 { 01288 if (__first != __last) 01289 { 01290 if (this != &__x) 01291 _M_check_equal_allocators(__x); 01292 01293 this->_M_transfer(__position, __first, __last); 01294 } 01295 } 01296 01297 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01298 void 01299 splice(iterator __position, list& __x, iterator __first, iterator __last) 01300 { splice(__position, std::move(__x), __first, __last); } 01301 #endif 01302 01303 /** 01304 * @brief Remove all elements equal to value. 01305 * @param value The value to remove. 01306 * 01307 * Removes every element in the list equal to @a value. 01308 * Remaining elements stay in list order. Note that this 01309 * function only erases the elements, and that if the elements 01310 * themselves are pointers, the pointed-to memory is not 01311 * touched in any way. Managing the pointer is the user's 01312 * responsibility. 01313 */ 01314 void 01315 remove(const _Tp& __value); 01316 01317 /** 01318 * @brief Remove all elements satisfying a predicate. 01319 * @param Predicate Unary predicate function or object. 01320 * 01321 * Removes every element in the list for which the predicate 01322 * returns true. Remaining elements stay in list order. Note 01323 * that this function only erases the elements, and that if the 01324 * elements themselves are pointers, the pointed-to memory is 01325 * not touched in any way. Managing the pointer is the user's 01326 * responsibility. 01327 */ 01328 template<typename _Predicate> 01329 void 01330 remove_if(_Predicate); 01331 01332 /** 01333 * @brief Remove consecutive duplicate elements. 01334 * 01335 * For each consecutive set of elements with the same value, 01336 * remove all but the first one. Remaining elements stay in 01337 * list order. Note that this function only erases the 01338 * elements, and that if the elements themselves are pointers, 01339 * the pointed-to memory is not touched in any way. Managing 01340 * the pointer is the user's responsibility. 01341 */ 01342 void 01343 unique(); 01344 01345 /** 01346 * @brief Remove consecutive elements satisfying a predicate. 01347 * @param BinaryPredicate Binary predicate function or object. 01348 * 01349 * For each consecutive set of elements [first,last) that 01350 * satisfy predicate(first,i) where i is an iterator in 01351 * [first,last), remove all but the first one. Remaining 01352 * elements stay in list order. Note that this function only 01353 * erases the elements, and that if the elements themselves are 01354 * pointers, the pointed-to memory is not touched in any way. 01355 * Managing the pointer is the user's responsibility. 01356 */ 01357 template<typename _BinaryPredicate> 01358 void 01359 unique(_BinaryPredicate); 01360 01361 /** 01362 * @brief Merge sorted lists. 01363 * @param x Sorted list to merge. 01364 * 01365 * Assumes that both @a x and this list are sorted according to 01366 * operator<(). Merges elements of @a x into this list in 01367 * sorted order, leaving @a x empty when complete. Elements in 01368 * this list precede elements in @a x that are equal. 01369 */ 01370 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01371 void 01372 merge(list&& __x); 01373 01374 void 01375 merge(list& __x) 01376 { merge(std::move(__x)); } 01377 #else 01378 void 01379 merge(list& __x); 01380 #endif 01381 01382 /** 01383 * @brief Merge sorted lists according to comparison function. 01384 * @param x Sorted list to merge. 01385 * @param StrictWeakOrdering Comparison function defining 01386 * sort order. 01387 * 01388 * Assumes that both @a x and this list are sorted according to 01389 * StrictWeakOrdering. Merges elements of @a x into this list 01390 * in sorted order, leaving @a x empty when complete. Elements 01391 * in this list precede elements in @a x that are equivalent 01392 * according to StrictWeakOrdering(). 01393 */ 01394 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01395 template<typename _StrictWeakOrdering> 01396 void 01397 merge(list&&, _StrictWeakOrdering); 01398 01399 template<typename _StrictWeakOrdering> 01400 void 01401 merge(list& __x, _StrictWeakOrdering __comp) 01402 { merge(std::move(__x), __comp); } 01403 #else 01404 template<typename _StrictWeakOrdering> 01405 void 01406 merge(list&, _StrictWeakOrdering); 01407 #endif 01408 01409 /** 01410 * @brief Reverse the elements in list. 01411 * 01412 * Reverse the order of elements in the list in linear time. 01413 */ 01414 void 01415 reverse() 01416 { this->_M_impl._M_node._M_reverse(); } 01417 01418 /** 01419 * @brief Sort the elements. 01420 * 01421 * Sorts the elements of this list in NlogN time. Equivalent 01422 * elements remain in list order. 01423 */ 01424 void 01425 sort(); 01426 01427 /** 01428 * @brief Sort the elements according to comparison function. 01429 * 01430 * Sorts the elements of this list in NlogN time. Equivalent 01431 * elements remain in list order. 01432 */ 01433 template<typename _StrictWeakOrdering> 01434 void 01435 sort(_StrictWeakOrdering); 01436 01437 protected: 01438 // Internal constructor functions follow. 01439 01440 // Called by the range constructor to implement [23.1.1]/9 01441 01442 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01443 // 438. Ambiguity in the "do the right thing" clause 01444 template<typename _Integer> 01445 void 01446 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) 01447 { _M_fill_initialize(static_cast<size_type>(__n), __x); } 01448 01449 // Called by the range constructor to implement [23.1.1]/9 01450 template<typename _InputIterator> 01451 void 01452 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, 01453 __false_type) 01454 { 01455 for (; __first != __last; ++__first) 01456 push_back(*__first); 01457 } 01458 01459 // Called by list(n,v,a), and the range constructor when it turns out 01460 // to be the same thing. 01461 void 01462 _M_fill_initialize(size_type __n, const value_type& __x) 01463 { 01464 for (; __n; --__n) 01465 push_back(__x); 01466 } 01467 01468 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01469 // Called by list(n). 01470 void 01471 _M_default_initialize(size_type __n) 01472 { 01473 for (; __n; --__n) 01474 emplace_back(); 01475 } 01476 01477 // Called by resize(sz). 01478 void 01479 _M_default_append(size_type __n); 01480 #endif 01481 01482 // Internal assign functions follow. 01483 01484 // Called by the range assign to implement [23.1.1]/9 01485 01486 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01487 // 438. Ambiguity in the "do the right thing" clause 01488 template<typename _Integer> 01489 void 01490 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) 01491 { _M_fill_assign(__n, __val); } 01492 01493 // Called by the range assign to implement [23.1.1]/9 01494 template<typename _InputIterator> 01495 void 01496 _M_assign_dispatch(_InputIterator __first, _InputIterator __last, 01497 __false_type); 01498 01499 // Called by assign(n,t), and the range assign when it turns out 01500 // to be the same thing. 01501 void 01502 _M_fill_assign(size_type __n, const value_type& __val); 01503 01504 01505 // Moves the elements from [first,last) before position. 01506 void 01507 _M_transfer(iterator __position, iterator __first, iterator __last) 01508 { __position._M_node->_M_transfer(__first._M_node, __last._M_node); } 01509 01510 // Inserts new element at position given and with value given. 01511 #ifndef __GXX_EXPERIMENTAL_CXX0X__ 01512 void 01513 _M_insert(iterator __position, const value_type& __x) 01514 { 01515 _Node* __tmp = _M_create_node(__x); 01516 __tmp->_M_hook(__position._M_node); 01517 } 01518 #else 01519 template<typename... _Args> 01520 void 01521 _M_insert(iterator __position, _Args&&... __args) 01522 { 01523 _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...); 01524 __tmp->_M_hook(__position._M_node); 01525 } 01526 #endif 01527 01528 // Erases element at position given. 01529 void 01530 _M_erase(iterator __position) 01531 { 01532 __position._M_node->_M_unhook(); 01533 _Node* __n = static_cast<_Node*>(__position._M_node); 01534 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01535 _M_get_Node_allocator().destroy(__n); 01536 #else 01537 _M_get_Tp_allocator().destroy(std::__addressof(__n->_M_data)); 01538 #endif 01539 _M_put_node(__n); 01540 } 01541 01542 // To implement the splice (and merge) bits of N1599. 01543 void 01544 _M_check_equal_allocators(list& __x) 01545 { 01546 if (std::__alloc_neq<typename _Base::_Node_alloc_type>:: 01547 _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator())) 01548 __throw_runtime_error(__N("list::_M_check_equal_allocators")); 01549 } 01550 }; 01551 01552 /** 01553 * @brief List equality comparison. 01554 * @param x A %list. 01555 * @param y A %list of the same type as @a x. 01556 * @return True iff the size and elements of the lists are equal. 01557 * 01558 * This is an equivalence relation. It is linear in the size of 01559 * the lists. Lists are considered equivalent if their sizes are 01560 * equal, and if corresponding elements compare equal. 01561 */ 01562 template<typename _Tp, typename _Alloc> 01563 inline bool 01564 operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 01565 { 01566 typedef typename list<_Tp, _Alloc>::const_iterator const_iterator; 01567 const_iterator __end1 = __x.end(); 01568 const_iterator __end2 = __y.end(); 01569 01570 const_iterator __i1 = __x.begin(); 01571 const_iterator __i2 = __y.begin(); 01572 while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) 01573 { 01574 ++__i1; 01575 ++__i2; 01576 } 01577 return __i1 == __end1 && __i2 == __end2; 01578 } 01579 01580 /** 01581 * @brief List ordering relation. 01582 * @param x A %list. 01583 * @param y A %list of the same type as @a x. 01584 * @return True iff @a x is lexicographically less than @a y. 01585 * 01586 * This is a total ordering relation. It is linear in the size of the 01587 * lists. The elements must be comparable with @c <. 01588 * 01589 * See std::lexicographical_compare() for how the determination is made. 01590 */ 01591 template<typename _Tp, typename _Alloc> 01592 inline bool 01593 operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 01594 { return std::lexicographical_compare(__x.begin(), __x.end(), 01595 __y.begin(), __y.end()); } 01596 01597 /// Based on operator== 01598 template<typename _Tp, typename _Alloc> 01599 inline bool 01600 operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 01601 { return !(__x == __y); } 01602 01603 /// Based on operator< 01604 template<typename _Tp, typename _Alloc> 01605 inline bool 01606 operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 01607 { return __y < __x; } 01608 01609 /// Based on operator< 01610 template<typename _Tp, typename _Alloc> 01611 inline bool 01612 operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 01613 { return !(__y < __x); } 01614 01615 /// Based on operator< 01616 template<typename _Tp, typename _Alloc> 01617 inline bool 01618 operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 01619 { return !(__x < __y); } 01620 01621 /// See std::list::swap(). 01622 template<typename _Tp, typename _Alloc> 01623 inline void 01624 swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) 01625 { __x.swap(__y); } 01626 01627 _GLIBCXX_END_NAMESPACE_CONTAINER 01628 } // namespace std 01629 01630 #endif /* _STL_LIST_H */