00001 // List implementation -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 2, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // You should have received a copy of the GNU General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00019 // USA. 00020 00021 // As a special exception, you may use this file as part of a free software 00022 // library without restriction. Specifically, if other files instantiate 00023 // templates or use macros or inline functions from this file, or you compile 00024 // this file and link it with other files to produce an executable, this 00025 // file does not by itself cause the resulting executable to be covered by 00026 // the GNU General Public License. This exception does not however 00027 // invalidate any other reasons why the executable file might be covered by 00028 // the GNU General Public License. 00029 00030 /* 00031 * 00032 * Copyright (c) 1994 00033 * Hewlett-Packard Company 00034 * 00035 * Permission to use, copy, modify, distribute and sell this software 00036 * and its documentation for any purpose is hereby granted without fee, 00037 * provided that the above copyright notice appear in all copies and 00038 * that both that copyright notice and this permission notice appear 00039 * in supporting documentation. Hewlett-Packard Company makes no 00040 * representations about the suitability of this software for any 00041 * purpose. It is provided "as is" without express or implied warranty. 00042 * 00043 * 00044 * Copyright (c) 1996,1997 00045 * Silicon Graphics Computer Systems, Inc. 00046 * 00047 * Permission to use, copy, modify, distribute and sell this software 00048 * and its documentation for any purpose is hereby granted without fee, 00049 * provided that the above copyright notice appear in all copies and 00050 * that both that copyright notice and this permission notice appear 00051 * in supporting documentation. Silicon Graphics makes no 00052 * representations about the suitability of this software for any 00053 * purpose. It is provided "as is" without express or implied warranty. 00054 */ 00055 00056 /** @file stl_list.h 00057 * This is an internal header file, included by other library headers. 00058 * You should not attempt to use it directly. 00059 */ 00060 00061 #ifndef _LIST_H 00062 #define _LIST_H 1 00063 00064 #include <bits/concept_check.h> 00065 00066 namespace _GLIBCXX_STD 00067 { 00068 // Supporting structures are split into common and templated types; the 00069 // latter publicly inherits from the former in an effort to reduce code 00070 // duplication. This results in some "needless" static_cast'ing later on, 00071 // but it's all safe downcasting. 00072 00073 /// @if maint Common part of a node in the %list. @endif 00074 struct _List_node_base 00075 { 00076 _List_node_base* _M_next; ///< Self-explanatory 00077 _List_node_base* _M_prev; ///< Self-explanatory 00078 00079 static void 00080 swap(_List_node_base& __x, _List_node_base& __y); 00081 00082 void 00083 transfer(_List_node_base * const __first, 00084 _List_node_base * const __last); 00085 00086 void 00087 reverse(); 00088 00089 void 00090 hook(_List_node_base * const __position); 00091 00092 void 00093 unhook(); 00094 }; 00095 00096 /// @if maint An actual node in the %list. @endif 00097 template<typename _Tp> 00098 struct _List_node : public _List_node_base 00099 { 00100 _Tp _M_data; ///< User's data. 00101 }; 00102 00103 /** 00104 * @brief A list::iterator. 00105 * 00106 * @if maint 00107 * All the functions are op overloads. 00108 * @endif 00109 */ 00110 template<typename _Tp> 00111 struct _List_iterator 00112 { 00113 typedef _List_iterator<_Tp> _Self; 00114 typedef _List_node<_Tp> _Node; 00115 00116 typedef ptrdiff_t difference_type; 00117 typedef bidirectional_iterator_tag iterator_category; 00118 typedef _Tp value_type; 00119 typedef _Tp* pointer; 00120 typedef _Tp& reference; 00121 00122 _List_iterator() 00123 : _M_node() { } 00124 00125 _List_iterator(_List_node_base* __x) 00126 : _M_node(__x) { } 00127 00128 // Must downcast from List_node_base to _List_node to get to _M_data. 00129 reference 00130 operator*() const 00131 { return static_cast<_Node*>(_M_node)->_M_data; } 00132 00133 pointer 00134 operator->() const 00135 { return &static_cast<_Node*>(_M_node)->_M_data; } 00136 00137 _Self& 00138 operator++() 00139 { 00140 _M_node = _M_node->_M_next; 00141 return *this; 00142 } 00143 00144 _Self 00145 operator++(int) 00146 { 00147 _Self __tmp = *this; 00148 _M_node = _M_node->_M_next; 00149 return __tmp; 00150 } 00151 00152 _Self& 00153 operator--() 00154 { 00155 _M_node = _M_node->_M_prev; 00156 return *this; 00157 } 00158 00159 _Self 00160 operator--(int) 00161 { 00162 _Self __tmp = *this; 00163 _M_node = _M_node->_M_prev; 00164 return __tmp; 00165 } 00166 00167 bool 00168 operator==(const _Self& __x) const 00169 { return _M_node == __x._M_node; } 00170 00171 bool 00172 operator!=(const _Self& __x) const 00173 { return _M_node != __x._M_node; } 00174 00175 // The only member points to the %list element. 00176 _List_node_base* _M_node; 00177 }; 00178 00179 /** 00180 * @brief A list::const_iterator. 00181 * 00182 * @if maint 00183 * All the functions are op overloads. 00184 * @endif 00185 */ 00186 template<typename _Tp> 00187 struct _List_const_iterator 00188 { 00189 typedef _List_const_iterator<_Tp> _Self; 00190 typedef const _List_node<_Tp> _Node; 00191 typedef _List_iterator<_Tp> iterator; 00192 00193 typedef ptrdiff_t difference_type; 00194 typedef bidirectional_iterator_tag iterator_category; 00195 typedef _Tp value_type; 00196 typedef const _Tp* pointer; 00197 typedef const _Tp& reference; 00198 00199 _List_const_iterator() 00200 : _M_node() { } 00201 00202 _List_const_iterator(const _List_node_base* __x) 00203 : _M_node(__x) { } 00204 00205 _List_const_iterator(const iterator& __x) 00206 : _M_node(__x._M_node) { } 00207 00208 // Must downcast from List_node_base to _List_node to get to 00209 // _M_data. 00210 reference 00211 operator*() const 00212 { return static_cast<_Node*>(_M_node)->_M_data; } 00213 00214 pointer 00215 operator->() const 00216 { return &static_cast<_Node*>(_M_node)->_M_data; } 00217 00218 _Self& 00219 operator++() 00220 { 00221 _M_node = _M_node->_M_next; 00222 return *this; 00223 } 00224 00225 _Self 00226 operator++(int) 00227 { 00228 _Self __tmp = *this; 00229 _M_node = _M_node->_M_next; 00230 return __tmp; 00231 } 00232 00233 _Self& 00234 operator--() 00235 { 00236 _M_node = _M_node->_M_prev; 00237 return *this; 00238 } 00239 00240 _Self 00241 operator--(int) 00242 { 00243 _Self __tmp = *this; 00244 _M_node = _M_node->_M_prev; 00245 return __tmp; 00246 } 00247 00248 bool 00249 operator==(const _Self& __x) const 00250 { return _M_node == __x._M_node; } 00251 00252 bool 00253 operator!=(const _Self& __x) const 00254 { return _M_node != __x._M_node; } 00255 00256 // The only member points to the %list element. 00257 const _List_node_base* _M_node; 00258 }; 00259 00260 template<typename _Val> 00261 inline bool 00262 operator==(const _List_iterator<_Val>& __x, 00263 const _List_const_iterator<_Val>& __y) 00264 { return __x._M_node == __y._M_node; } 00265 00266 template<typename _Val> 00267 inline bool 00268 operator!=(const _List_iterator<_Val>& __x, 00269 const _List_const_iterator<_Val>& __y) 00270 { return __x._M_node != __y._M_node; } 00271 00272 00273 /** 00274 * @if maint 00275 * See bits/stl_deque.h's _Deque_base for an explanation. 00276 * @endif 00277 */ 00278 template<typename _Tp, typename _Alloc> 00279 class _List_base 00280 { 00281 protected: 00282 // NOTA BENE 00283 // The stored instance is not actually of "allocator_type"'s 00284 // type. Instead we rebind the type to 00285 // Allocator<List_node<Tp>>, which according to [20.1.5]/4 00286 // should probably be the same. List_node<Tp> is not the same 00287 // size as Tp (it's two pointers larger), and specializations on 00288 // Tp may go unused because List_node<Tp> is being bound 00289 // instead. 00290 // 00291 // We put this to the test in the constructors and in 00292 // get_allocator, where we use conversions between 00293 // allocator_type and _Node_Alloc_type. The conversion is 00294 // required by table 32 in [20.1.5]. 00295 typedef typename _Alloc::template rebind<_List_node<_Tp> >::other 00296 00297 _Node_Alloc_type; 00298 00299 struct _List_impl 00300 : public _Node_Alloc_type { 00301 _List_node_base _M_node; 00302 _List_impl (const _Node_Alloc_type& __a) 00303 : _Node_Alloc_type(__a) 00304 { } 00305 }; 00306 00307 _List_impl _M_impl; 00308 00309 _List_node<_Tp>* 00310 _M_get_node() 00311 { return _M_impl._Node_Alloc_type::allocate(1); } 00312 00313 void 00314 _M_put_node(_List_node<_Tp>* __p) 00315 { _M_impl._Node_Alloc_type::deallocate(__p, 1); } 00316 00317 public: 00318 typedef _Alloc allocator_type; 00319 00320 allocator_type 00321 get_allocator() const 00322 { return allocator_type(*static_cast<const _Node_Alloc_type*>(&this->_M_impl)); } 00323 00324 _List_base(const allocator_type& __a) 00325 : _M_impl(__a) 00326 { _M_init(); } 00327 00328 // This is what actually destroys the list. 00329 ~_List_base() 00330 { _M_clear(); } 00331 00332 void 00333 _M_clear(); 00334 00335 void 00336 _M_init() 00337 { 00338 this->_M_impl._M_node._M_next = &this->_M_impl._M_node; 00339 this->_M_impl._M_node._M_prev = &this->_M_impl._M_node; 00340 } 00341 }; 00342 00343 /** 00344 * @brief A standard container with linear time access to elements, 00345 * and fixed time insertion/deletion at any point in the sequence. 00346 * 00347 * @ingroup Containers 00348 * @ingroup Sequences 00349 * 00350 * Meets the requirements of a <a href="tables.html#65">container</a>, a 00351 * <a href="tables.html#66">reversible container</a>, and a 00352 * <a href="tables.html#67">sequence</a>, including the 00353 * <a href="tables.html#68">optional sequence requirements</a> with the 00354 * %exception of @c at and @c operator[]. 00355 * 00356 * This is a @e doubly @e linked %list. Traversal up and down the 00357 * %list requires linear time, but adding and removing elements (or 00358 * @e nodes) is done in constant time, regardless of where the 00359 * change takes place. Unlike std::vector and std::deque, 00360 * random-access iterators are not provided, so subscripting ( @c 00361 * [] ) access is not allowed. For algorithms which only need 00362 * sequential access, this lack makes no difference. 00363 * 00364 * Also unlike the other standard containers, std::list provides 00365 * specialized algorithms %unique to linked lists, such as 00366 * splicing, sorting, and in-place reversal. 00367 * 00368 * @if maint 00369 * A couple points on memory allocation for list<Tp>: 00370 * 00371 * First, we never actually allocate a Tp, we allocate 00372 * List_node<Tp>'s and trust [20.1.5]/4 to DTRT. This is to ensure 00373 * that after elements from %list<X,Alloc1> are spliced into 00374 * %list<X,Alloc2>, destroying the memory of the second %list is a 00375 * valid operation, i.e., Alloc1 giveth and Alloc2 taketh away. 00376 * 00377 * Second, a %list conceptually represented as 00378 * @code 00379 * A <---> B <---> C <---> D 00380 * @endcode 00381 * is actually circular; a link exists between A and D. The %list 00382 * class holds (as its only data member) a private list::iterator 00383 * pointing to @e D, not to @e A! To get to the head of the %list, 00384 * we start at the tail and move forward by one. When this member 00385 * iterator's next/previous pointers refer to itself, the %list is 00386 * %empty. @endif 00387 */ 00388 template<typename _Tp, typename _Alloc = allocator<_Tp> > 00389 class list : protected _List_base<_Tp, _Alloc> 00390 { 00391 // concept requirements 00392 __glibcxx_class_requires(_Tp, _SGIAssignableConcept) 00393 00394 typedef _List_base<_Tp, _Alloc> _Base; 00395 00396 public: 00397 typedef _Tp value_type; 00398 typedef typename _Alloc::pointer pointer; 00399 typedef typename _Alloc::const_pointer const_pointer; 00400 typedef typename _Alloc::reference reference; 00401 typedef typename _Alloc::const_reference const_reference; 00402 typedef _List_iterator<_Tp> iterator; 00403 typedef _List_const_iterator<_Tp> const_iterator; 00404 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00405 typedef std::reverse_iterator<iterator> reverse_iterator; 00406 typedef size_t size_type; 00407 typedef ptrdiff_t difference_type; 00408 typedef typename _Base::allocator_type allocator_type; 00409 00410 protected: 00411 // Note that pointers-to-_Node's can be ctor-converted to 00412 // iterator types. 00413 typedef _List_node<_Tp> _Node; 00414 00415 /** @if maint 00416 * One data member plus two memory-handling functions. If the 00417 * _Alloc type requires separate instances, then one of those 00418 * will also be included, accumulated from the topmost parent. 00419 * @endif 00420 */ 00421 using _Base::_M_impl; 00422 using _Base::_M_put_node; 00423 using _Base::_M_get_node; 00424 00425 /** 00426 * @if maint 00427 * @param x An instance of user data. 00428 * 00429 * Allocates space for a new node and constructs a copy of @a x in it. 00430 * @endif 00431 */ 00432 _Node* 00433 _M_create_node(const value_type& __x) 00434 { 00435 _Node* __p = this->_M_get_node(); 00436 try 00437 { 00438 std::_Construct(&__p->_M_data, __x); 00439 } 00440 catch(...) 00441 { 00442 _M_put_node(__p); 00443 __throw_exception_again; 00444 } 00445 return __p; 00446 } 00447 00448 /** 00449 * @if maint 00450 * Allocates space for a new node and default-constructs a new 00451 * instance of @c value_type in it. 00452 * @endif 00453 */ 00454 _Node* 00455 _M_create_node() 00456 { 00457 _Node* __p = this->_M_get_node(); 00458 try 00459 { 00460 std::_Construct(&__p->_M_data); 00461 } 00462 catch(...) 00463 { 00464 _M_put_node(__p); 00465 __throw_exception_again; 00466 } 00467 return __p; 00468 } 00469 00470 public: 00471 // [23.2.2.1] construct/copy/destroy 00472 // (assign() and get_allocator() are also listed in this section) 00473 /** 00474 * @brief Default constructor creates no elements. 00475 */ 00476 explicit 00477 list(const allocator_type& __a = allocator_type()) 00478 : _Base(__a) { } 00479 00480 /** 00481 * @brief Create a %list with copies of an exemplar element. 00482 * @param n The number of elements to initially create. 00483 * @param value An element to copy. 00484 * 00485 * This constructor fills the %list with @a n copies of @a value. 00486 */ 00487 list(size_type __n, const value_type& __value, 00488 const allocator_type& __a = allocator_type()) 00489 : _Base(__a) 00490 { this->insert(begin(), __n, __value); } 00491 00492 /** 00493 * @brief Create a %list with default elements. 00494 * @param n The number of elements to initially create. 00495 * 00496 * This constructor fills the %list with @a n copies of a 00497 * default-constructed element. 00498 */ 00499 explicit 00500 list(size_type __n) 00501 : _Base(allocator_type()) 00502 { this->insert(begin(), __n, value_type()); } 00503 00504 /** 00505 * @brief %List copy constructor. 00506 * @param x A %list of identical element and allocator types. 00507 * 00508 * The newly-created %list uses a copy of the allocation object used 00509 * by @a x. 00510 */ 00511 list(const list& __x) 00512 : _Base(__x.get_allocator()) 00513 { this->insert(begin(), __x.begin(), __x.end()); } 00514 00515 /** 00516 * @brief Builds a %list from a range. 00517 * @param first An input iterator. 00518 * @param last An input iterator. 00519 * 00520 * Create a %list consisting of copies of the elements from 00521 * [@a first,@a last). This is linear in N (where N is 00522 * distance(@a first,@a last)). 00523 * 00524 * @if maint 00525 * We don't need any dispatching tricks here, because insert does all of 00526 * that anyway. 00527 * @endif 00528 */ 00529 template<typename _InputIterator> 00530 list(_InputIterator __first, _InputIterator __last, 00531 const allocator_type& __a = allocator_type()) 00532 : _Base(__a) 00533 { this->insert(begin(), __first, __last); } 00534 00535 /** 00536 * No explicit dtor needed as the _Base dtor takes care of 00537 * things. The _Base dtor only erases the elements, and note 00538 * that if the elements themselves are pointers, the pointed-to 00539 * memory is not touched in any way. Managing the pointer is 00540 * the user's responsibilty. 00541 */ 00542 00543 /** 00544 * @brief %List assignment operator. 00545 * @param x A %list of identical element and allocator types. 00546 * 00547 * All the elements of @a x are copied, but unlike the copy 00548 * constructor, the allocator object is not copied. 00549 */ 00550 list& 00551 operator=(const list& __x); 00552 00553 /** 00554 * @brief Assigns a given value to a %list. 00555 * @param n Number of elements to be assigned. 00556 * @param val Value to be assigned. 00557 * 00558 * This function fills a %list with @a n copies of the given 00559 * value. Note that the assignment completely changes the %list 00560 * and that the resulting %list's size is the same as the number 00561 * of elements assigned. Old data may be lost. 00562 */ 00563 void 00564 assign(size_type __n, const value_type& __val) 00565 { _M_fill_assign(__n, __val); } 00566 00567 /** 00568 * @brief Assigns a range to a %list. 00569 * @param first An input iterator. 00570 * @param last An input iterator. 00571 * 00572 * This function fills a %list with copies of the elements in the 00573 * range [@a first,@a last). 00574 * 00575 * Note that the assignment completely changes the %list and 00576 * that the resulting %list's size is the same as the number of 00577 * elements assigned. Old data may be lost. 00578 */ 00579 template<typename _InputIterator> 00580 void 00581 assign(_InputIterator __first, _InputIterator __last) 00582 { 00583 // Check whether it's an integral type. If so, it's not an iterator. 00584 typedef typename _Is_integer<_InputIterator>::_Integral _Integral; 00585 _M_assign_dispatch(__first, __last, _Integral()); 00586 } 00587 00588 /// Get a copy of the memory allocation object. 00589 allocator_type 00590 get_allocator() const 00591 { return _Base::get_allocator(); } 00592 00593 // iterators 00594 /** 00595 * Returns a read/write iterator that points to the first element in the 00596 * %list. Iteration is done in ordinary element order. 00597 */ 00598 iterator 00599 begin() 00600 { return this->_M_impl._M_node._M_next; } 00601 00602 /** 00603 * Returns a read-only (constant) iterator that points to the 00604 * first element in the %list. Iteration is done in ordinary 00605 * element order. 00606 */ 00607 const_iterator 00608 begin() const 00609 { return this->_M_impl._M_node._M_next; } 00610 00611 /** 00612 * Returns a read/write iterator that points one past the last 00613 * element in the %list. Iteration is done in ordinary element 00614 * order. 00615 */ 00616 iterator 00617 end() { return &this->_M_impl._M_node; } 00618 00619 /** 00620 * Returns a read-only (constant) iterator that points one past 00621 * the last element in the %list. Iteration is done in ordinary 00622 * element order. 00623 */ 00624 const_iterator 00625 end() const 00626 { return &this->_M_impl._M_node; } 00627 00628 /** 00629 * Returns a read/write reverse iterator that points to the last 00630 * element in the %list. Iteration is done in reverse element 00631 * order. 00632 */ 00633 reverse_iterator 00634 rbegin() 00635 { return reverse_iterator(end()); } 00636 00637 /** 00638 * Returns a read-only (constant) reverse iterator that points to 00639 * the last element in the %list. Iteration is done in reverse 00640 * element order. 00641 */ 00642 const_reverse_iterator 00643 rbegin() const 00644 { return const_reverse_iterator(end()); } 00645 00646 /** 00647 * Returns a read/write reverse iterator that points to one 00648 * before the first element in the %list. Iteration is done in 00649 * reverse element order. 00650 */ 00651 reverse_iterator 00652 rend() 00653 { return reverse_iterator(begin()); } 00654 00655 /** 00656 * Returns a read-only (constant) reverse iterator that points to one 00657 * before the first element in the %list. Iteration is done in reverse 00658 * element order. 00659 */ 00660 const_reverse_iterator 00661 rend() const 00662 { return const_reverse_iterator(begin()); } 00663 00664 // [23.2.2.2] capacity 00665 /** 00666 * Returns true if the %list is empty. (Thus begin() would equal 00667 * end().) 00668 */ 00669 bool 00670 empty() const 00671 { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; } 00672 00673 /** Returns the number of elements in the %list. */ 00674 size_type 00675 size() const 00676 { return std::distance(begin(), end()); } 00677 00678 /** Returns the size() of the largest possible %list. */ 00679 size_type 00680 max_size() const 00681 { return size_type(-1); } 00682 00683 /** 00684 * @brief Resizes the %list to the specified number of elements. 00685 * @param new_size Number of elements the %list should contain. 00686 * @param x Data with which new elements should be populated. 00687 * 00688 * This function will %resize the %list to the specified number 00689 * of elements. If the number is smaller than the %list's 00690 * current size the %list is truncated, otherwise the %list is 00691 * extended and new elements are populated with given data. 00692 */ 00693 void 00694 resize(size_type __new_size, const value_type& __x); 00695 00696 /** 00697 * @brief Resizes the %list to the specified number of elements. 00698 * @param new_size Number of elements the %list should contain. 00699 * 00700 * This function will resize the %list to the specified number of 00701 * elements. If the number is smaller than the %list's current 00702 * size the %list is truncated, otherwise the %list is extended 00703 * and new elements are default-constructed. 00704 */ 00705 void 00706 resize(size_type __new_size) 00707 { this->resize(__new_size, value_type()); } 00708 00709 // element access 00710 /** 00711 * Returns a read/write reference to the data at the first 00712 * element of the %list. 00713 */ 00714 reference 00715 front() 00716 { return *begin(); } 00717 00718 /** 00719 * Returns a read-only (constant) reference to the data at the first 00720 * element of the %list. 00721 */ 00722 const_reference 00723 front() const 00724 { return *begin(); } 00725 00726 /** 00727 * Returns a read/write reference to the data at the last element 00728 * of the %list. 00729 */ 00730 reference 00731 back() 00732 { return *(--end()); } 00733 00734 /** 00735 * Returns a read-only (constant) reference to the data at the last 00736 * element of the %list. 00737 */ 00738 const_reference 00739 back() const 00740 { return *(--end()); } 00741 00742 // [23.2.2.3] modifiers 00743 /** 00744 * @brief Add data to the front of the %list. 00745 * @param x Data to be added. 00746 * 00747 * This is a typical stack operation. The function creates an 00748 * element at the front of the %list and assigns the given data 00749 * to it. Due to the nature of a %list this operation can be 00750 * done in constant time, and does not invalidate iterators and 00751 * references. 00752 */ 00753 void 00754 push_front(const value_type& __x) 00755 { this->_M_insert(begin(), __x); } 00756 00757 /** 00758 * @brief Removes first element. 00759 * 00760 * This is a typical stack operation. It shrinks the %list by 00761 * one. Due to the nature of a %list this operation can be done 00762 * in constant time, and only invalidates iterators/references to 00763 * the element being removed. 00764 * 00765 * Note that no data is returned, and if the first element's data 00766 * is needed, it should be retrieved before pop_front() is 00767 * called. 00768 */ 00769 void 00770 pop_front() 00771 { this->_M_erase(begin()); } 00772 00773 /** 00774 * @brief Add data to the end of the %list. 00775 * @param x Data to be added. 00776 * 00777 * This is a typical stack operation. The function creates an 00778 * element at the end of the %list and assigns the given data to 00779 * it. Due to the nature of a %list this operation can be done 00780 * in constant time, and does not invalidate iterators and 00781 * references. 00782 */ 00783 void 00784 push_back(const value_type& __x) 00785 { this->_M_insert(nst 00573 * range [@a first,@a last). 00574 * 00575 * Note that the assignment completely changes the %list and 00576 * that the resulting %list's size is the same as the number of 00577 * elements assigned. Old data may be lost. 00578 */ 00579 template<typename _InputIterator> 00580 void 00581 assign(_InputIterator __first, _InputIterator __last) 00582 { 00583 // Check whether it's an integral type. If so, it's not an iterator. 00584 typedef typename _Is_integer<_InputIterator>::_Integral _Integral; 00585 _M_assign_dispatch(__first, __last, _Integral()); 00586 } 00587 00588 /// Get a copy of the memory allocation object. 00589 allocator_type 00590 get_allocator() const 00591 { return _Base::get_allocator(); } 00592 00593 // iterators 00594 /** 00595 * Returns a read/write iterator that points to the first element in the 00596 * %list. Iteration is done in ordinary element order. 00597 */ 00598 iterator 00599 begin() 00600 { return this->_M_impl._M_node._M_next; } 00601 00602 /** 00603 * Returns a read-only (constant) iterator that points to the 00604 * first element in the %list. Iteration is done in ordinary 00605 * element order. 00606 */ 00607 const_iterator 00608 begin() const 00609 { return this->_M_impl._M_node._M_next; } 00610 00611 /** 00612 * Returns a read/write iterator that points one past the last 00613 * element in the %list. Iteration is done in ordinary element 00614 * order. 00615 */ 00616 iterator 00617 end() { return &this->_M_impl._M_node; } 00618 00619 /** 00620 * Returns a read-only (constant) iterator that points one past 00621 * the last element in the %list. Iteration is done in ordinary 00622 * element order. 00623 */ 00624 const_iterator 00625 end() const 00626 { return &this->_M_impl._M_node; } 00627 00628 /** 00629 * Returns a read/write reverse iterator that points to the last 00630 * element in the %list. Iteration is done in reverse element 00631 * order. 00632 */ 00633 reverse_iterator 00634 rbegin() 00635 { return reverse_iterator(end()); } 00636 00637 /** 00638 * Returns a read-only (constant) reverse iterator that points to 00639 * the last element in the %list. Iteration is done in reverse 00640 * element order. 00641 */ 00642 const_reverse_iterator 00643 rbegin() const 00644 { return const_reverse_iterator(end()); } 00645 00646 /** 00647 * Returns a read/write reverse iterator that points to one 00648 * before the first element in the %list. Iteration is done in 00649 * reverse element order. 00650 */ 00651 reverse_iterator 00652 rend() 00653 { return reverse_iterator(begin()); } 00654 00655 /** 00656 * Returns a read-only (constant) reverse iterator that points to one 00657 * before the first element in the %list. Iteration is done in reverse 00658 * element order. 00659 */ 00660 const_reverse_iterator 00661 rend() const 00662 { return const_reverse_iterator(begin()); } 00663 00664 // [23.2.2.2] capacity 00665 /** 00666 * Returns true if the %list is empty. (Thus begin() would equal 00667 * end().) 00668 */ 00669 bool 00670 empty() const 00671 { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; } 00672 00673 /** Returns the number of elements in the %list. */ 00674 size_type 00675 size() const 00676 { return std::distance(begin(), end()); } 00677 00678 /** Returns the size() of the largest possible %list. */ 00679 size_type 00680 max_size() const 00681 { return size_type(-1); } 00682 00683 /** 00684 * @brief Resizes the %list to the specified number of elements. 00685 * @param new_size Number of elements the %list should contain. 00686 * @param x Data with which new elements should be populated. 00687 * 00688 * This function will %resize the %list to the specified number 00689 * of elements. If the number is smaller than the %list's 00690 * current size the %list is truncated, otherwise the %list is 00691 * extended and new elements are populated with given data. 00692 */ 00693 void 00694 resize(size_type __new_size, const value_type& __x); 00695 00696 /** 00697 * @brief Resizes the %list to the specified number of elements. 00698 * @param new_size Number of elements the %list should contain. 00699 * 00700 * This function will resize the %list to the specified number of 00701 * elements. If the number is smaller than the %list's current 00702 * size the %list is truncated, otherwise the %list is extended 00703 * and new elements are default-constructed. 00704 */ 00705 void 00706 resize(size_type __new_size) 00707 { this->resize(__new_size, value_type()); } 00708 00709 // element access 00710 /** 00711 * Returns a read/write reference to the data at the first 00712 * element of the %list. 00713 */ 00714 reference 00715 front() 00716 { return *begin(); } 00717 00718 /** 00719 * Returns a read-only (constant) reference to the data at the first 00720 * element of the %list. 00721 */ 00722 const_reference 00723 front() const 00724 { return *begin(); } 00725 00726 /** 00727 * Returns a read/write reference to the data at the last element 00728 * of the %list. 00729 */ 00730 reference 00731 back() 00732 { return *(--end()); } 00733 00734 /** 00735 * Returns a read-only (constant) reference to the data at the last 00736 * element of the %list. 00737 */ 00738 const_reference 00739 back() const 00740 { return *(--end()); } 00741 00742 // [23.2.2.3] modifiers 00743 /** 00744 * @brief Add data to the front of the %list. 00745 * @param x Data to be added. 00746 * 00747 * This is a typical stack operation. The function creates an 00748 * element at the front of the %list and assigns the given data 00749 * to it. Due to the nature of a %list this operation can be 00750 * done in constant time, and does not invalidate iterators and 00751 * references. 00752 */ 00753 void 00754 push_front(const value_type& __x) 00755 { this->_M_insert(begin(), __x); } 00756 00757 /** 00758 * @brief Removes first element. 00759 * 00760 * This is a typical stack operation. It shrinks the %list by 00761 * one. Due to the nature of a %list this operation can be done 00762 * in constant time, and only invalidates iterators/references to 00763 * the element being removed. 00764 * 00765 * Note that no data is returned, and if the first element's data 00766 * is needed, it should be retrieved before pop_front() is 00767 * called. 00768 */ 00769 void 00770 pop_front() 00771 { this->_M_erase(begin()); } 00772 00773 /** 00774 * @brief Add data to the end of the %list. 00775 * @param x Data to be added. 00776 * 00777 * This is a typical stack operation. The function creates an 00778 * element at the end of the %list and assigns the given data to 00779 * it. Due to the nature of a %list this operation can be done 00780 * in constant time, and does not invalidate iterators and 00781 * references. 00782 */ 00783 void 00784 push_back(const value_type& __x) 00785 { this->_M_insert(nst 00573 * range [@a first,@a last). 00574 * 00575 * Note that the assignment completely changes the %list and 00576 * that the resulting %list's size is the same as the number of 00577 * elements assigned. Old data may be lost. 00578 */ 00579 template<typename _InputIterator> 00580 void 00581 assign(_InputIterator __first, _InputIterator __last) 00582 { 00583 // Check whether it's an integral type. If so, it's not an iterator. 00584 typedef typename _Is_integer<_InputIterator>::_Integral _Integral; 00585 _M_assign_dispatch(__first, __last, _Integral()); 00586 } 00587 00588 /// Get a copy of the memory allocation object. 00589 allocator_type 00590 get_allocator() const 00591 { return _Base::get_allocator(); } 00592 00593 // iterators 00594 /** 00595 * Returns a read/write iterator that points to the first element in the 00596 * %list. Iteration is done in ordinary element order. 00597 */ 00598 iterator 00599 begin() 00600 { return this->_M_impl._M_node._M_next; } 00601 00602 /** 00603 * Returns a read-only (constant) iterator that points to the 00604 * first element in the %list. Iteration is done in ordinary 00605 * element order. 00606 */ 00607 const_iterator 00608 begin() const 00609 { return this->_M_impl._M_node._M_next; } 00610 00611 /** 00612 * Returns a read/write iterator that points one past the last 00613 * element in the %list. Iteration is done in ordinary element 00614 * order. 00615 */ 00616 iterator 00617 end() { return &this->_M_impl._M_node; } 00618 00619 /** 00620 * Returns a read-only (constant) iterator that points one past 00621 * the last element in the %list. Iteration is done in ordinary 00622 * element order. 00623 */ 00624 const_iterator 00625 end() const 00626 { return &this->_M_impl._M_node; } 00627 00628 /** 00629 * Returns a read/write reverse iterator that points to the last 00630 * element in the %list. Iteration is done in reverse element 00631 * order. 00632 */ 00633 reverse_iterator 00634 rbegin() 00635 { return reverse_iterator(end()); } 00636 00637 /** 00638 * Returns a read-only (constant) reverse iterator that points to 00639 * the last element in the %list. Iteration is done in reverse 00640 * element order. 00641 */ 00642 const_reverse_iterator 00643 rbegin() const 00644 { return const_reverse_iterator(end()); } 00645 00646 /** 00647 * Returns a read/write reverse iterator that points to one 00648 * before the first element in the %list. Iteration is done in 00649 * reverse element order. 00650 */ 00651 reverse_iterator 00652 rend() 00653 { return reverse_iterator(begin()); } 00654 00655 /** 00656 * Returns a read-only (constant) reverse iterator that points to one 00657 * before the first element in the %list. Iteration is done in reverse 00658 * element order. 00659 */ 00660 const_reverse_iterator 00661 rend() const 00662 { return const_reverse_iterator(begin()); } 00663 00664 // [23.2.2.2] capacity 00665 /** 00666 * Returns true if the %list is empty. (Thus begin() would equal 00667 * end().) 00668 */ 00669 bool 00670 empty() const 00671 { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; } 00672 00673 /** Returns the number of elements in the %list. */ 00674 size_type 00675 size() const 00676 { return std::distance(begin(), end()); } 00677 00678 /** Returns the size() of the largest possible %list. */ 00679 size_type 00680 max_size() const 00681 { return size_type(-1); } 00682 00683 /** 00684 * @brief Resizes the %list to the specified number of elements. 00685 * @param new_size Number of elements the %list should contain. 00686 * @param x Data with which new elements should be populated. 00687 * 00688 * This function will %resize the %list to the specified number 00689 * of elements. If the number is smaller than the %list's 00690 * current size the %list is truncated, otherwise the %list is 00691 * extended and new elements are populated with given data. 00692 */ 00693 void 00694 resize(size_type __new_size, const value_type& __x); 00695 00696 /** 00697 * @brief Resizes the %list to the specified number of elements. 00698 * @param new_size Number of elements the %list should contain. 00699 * 00700 * This function will resize the %list to the specified number of 00701 * elements. If the number is smaller than the %list's current 00702 * size the %list is truncated, otherwise the %list is extended 00703 * and new elements are default-constructed. 00704 */ 00705 void 00706 resize(size_type __new_size) 00707 { this->resize(__new_size, value_type()); } 00708 00709 // element access 00710 /** 00711 * Returns a read/write reference to the data at the first 00712 * element of the %list. 00713 */ 00714 reference 00715 front() 00716 { return *begin(); } 00717 00718 /** 00719 * Returns a read-only (constant) reference to the data at the first 00720 * element of the %list. 00721 */ 00722 const_reference 00723 front() const 00724 { return *begin(); } 00725 00726 /** 00727 * Returns a read/write reference to the data at the last element 00728 * of the %list. 00729 */ 00730 reference 00731 back() 00732 { return *(--end()); } 00733 00734 /** 00735 * Returns a read-only (constant) reference to the data at the last 00736 * element of the %list. 00737 */ 00738 const_reference 00739 back() const 00740 { return *(--end()); } 00741 00742 // [23.2.2.3] modifiers 00743 /** 00744 * @brief Add data to the front of the %list. 00745 * @param x Data to be added. 00746 * 00747 * This is a typical stack operation. The function creates an 00748 * element at the front of the %list and assigns the given data 00749 * to it. Due to the nature of a %list this operation can be 00750 * done in constant time, and does not invalidate iterators and 00751 * references. 00752 */ 00753 void 00754 push_front(const value_type& __x) 00755 { this->_M_insert(begin(), __x); } 00756 00757 /** 00758 * @brief Removes first element. 00759 * 00760 * This is a typical stack operation. It shrinks the %list by 00761 * one. Due to the nature of a %list this operation can be done 00762 * in constant time, and only invalidates iterators/references to 00763 * the element being removed. 00764 * 00765 * Note that no data is returned, and if the first element's data 00766 * is needed, it should be retrieved before pop_front() is 00767 * called. 00768 */ 00769 void 00770 pop_front() 00771 { this->_M_erase(begin()); } 00772 00773 /** 00774 * @brief Add data to the end of the %list. 00775 * @param x Data to be added. 00776 * 00777 * This is a typical stack operation. The function creates an 00778 * element at the end of the %list and assigns the given data to 00779 * it. Due to the nature of a %list this operation can be done 00780 * in constant time, and does not invalidate iterators and 00781 * references. 00782 */ 00783 void 00784 push_back(const value_type& __x) 00785 { this->_M_insert(nst 00573 * range [@a first,@a last). 00574 * 00575 * Note that the assignment completely changes the %list and 00576 * that the resulting %list's size is the same as the number of 00577 * elements assigned. Old data may be lost. 00578 */ 00579 template<typename _InputIterator> 00580 void 00581 assign(_InputIterator __first, _InputIterator __last) 00582 { 00583 // Check whether it's an integral type. If so, it's not an iterator. 00584 typedef typename _Is_integer<_InputIterator>::_Integral _Integral; 00585 _M_assign_dispatch(__first, __last, _Integral()); 00586 } 00587 00588 /// Get a copy of the memory allocation object. 00589 allocator_type 00590 get_allocator() const 00591 { return _Base::get_allocator(); } 00592 00593 // iterators 00594 /** 00595 * Returns a read/write iterator that points to the first element in the 00596 * %list. Iteration is done in ordinary element order. 00597 */ 00598 iterator 00599 begin() 00600 { return this->_M_impl._M_node._M_next; } 00601 00602 /** 00603 * Returns a read-only (constant) iterator that points to the 00604 * first element in the %list. Iteration is done in ordinary 00605 * element order. 00606 */ 00607 const_iterator 00608 begin() const 00609 { return this->_M_impl._M_node._M_next; } 00610 00611 /** 00612 * Returns a read/write iterator that points one past the last 00613 * element in the %list. Iteration is done in ordinary element 00614 * order. 00615 */ 00616 iterator 00617 end() { return &this->_M_impl._M_node; } 00618 00619 /** 00620