|
libstdc++
|
00001 // Deque implementation -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 00004 // 2011, 2012 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) 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_deque.h 00053 * This is an internal header file, included by other library headers. 00054 * Do not attempt to use it directly. @headername{deque} 00055 */ 00056 00057 #ifndef _STL_DEQUE_H 00058 #define _STL_DEQUE_H 1 00059 00060 #include <bits/concept_check.h> 00061 #include <bits/stl_iterator_base_types.h> 00062 #include <bits/stl_iterator_base_funcs.h> 00063 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00064 #include <initializer_list> 00065 #endif 00066 00067 namespace std _GLIBCXX_VISIBILITY(default) 00068 { 00069 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER 00070 00071 /** 00072 * @brief This function controls the size of memory nodes. 00073 * @param __size The size of an element. 00074 * @return The number (not byte size) of elements per node. 00075 * 00076 * This function started off as a compiler kludge from SGI, but 00077 * seems to be a useful wrapper around a repeated constant 00078 * expression. The @b 512 is tunable (and no other code needs to 00079 * change), but no investigation has been done since inheriting the 00080 * SGI code. Touch _GLIBCXX_DEQUE_BUF_SIZE only if you know what 00081 * you are doing, however: changing it breaks the binary 00082 * compatibility!! 00083 */ 00084 00085 #ifndef _GLIBCXX_DEQUE_BUF_SIZE 00086 #define _GLIBCXX_DEQUE_BUF_SIZE 512 00087 #endif 00088 00089 inline size_t 00090 __deque_buf_size(size_t __size) 00091 { return (__size < _GLIBCXX_DEQUE_BUF_SIZE 00092 ? size_t(_GLIBCXX_DEQUE_BUF_SIZE / __size) : size_t(1)); } 00093 00094 00095 /** 00096 * @brief A deque::iterator. 00097 * 00098 * Quite a bit of intelligence here. Much of the functionality of 00099 * deque is actually passed off to this class. A deque holds two 00100 * of these internally, marking its valid range. Access to 00101 * elements is done as offsets of either of those two, relying on 00102 * operator overloading in this class. 00103 * 00104 * All the functions are op overloads except for _M_set_node. 00105 */ 00106 template<typename _Tp, typename _Ref, typename _Ptr> 00107 struct _Deque_iterator 00108 { 00109 typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator; 00110 typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator; 00111 00112 static size_t _S_buffer_size() 00113 { return __deque_buf_size(sizeof(_Tp)); } 00114 00115 typedef std::random_access_iterator_tag iterator_category; 00116 typedef _Tp value_type; 00117 typedef _Ptr pointer; 00118 typedef _Ref reference; 00119 typedef size_t size_type; 00120 typedef ptrdiff_t difference_type; 00121 typedef _Tp** _Map_pointer; 00122 typedef _Deque_iterator _Self; 00123 00124 _Tp* _M_cur; 00125 _Tp* _M_first; 00126 _Tp* _M_last; 00127 _Map_pointer _M_node; 00128 00129 _Deque_iterator(_Tp* __x, _Map_pointer __y) 00130 : _M_cur(__x), _M_first(*__y), 00131 _M_last(*__y + _S_buffer_size()), _M_node(__y) { } 00132 00133 _Deque_iterator() 00134 : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) { } 00135 00136 _Deque_iterator(const iterator& __x) 00137 : _M_cur(__x._M_cur), _M_first(__x._M_first), 00138 _M_last(__x._M_last), _M_node(__x._M_node) { } 00139 00140 reference 00141 operator*() const 00142 { return *_M_cur; } 00143 00144 pointer 00145 operator->() const 00146 { return _M_cur; } 00147 00148 _Self& 00149 operator++() 00150 { 00151 ++_M_cur; 00152 if (_M_cur == _M_last) 00153 { 00154 _M_set_node(_M_node + 1); 00155 _M_cur = _M_first; 00156 } 00157 return *this; 00158 } 00159 00160 _Self 00161 operator++(int) 00162 { 00163 _Self __tmp = *this; 00164 ++*this; 00165 return __tmp; 00166 } 00167 00168 _Self& 00169 operator--() 00170 { 00171 if (_M_cur == _M_first) 00172 { 00173 _M_set_node(_M_node - 1); 00174 _M_cur = _M_last; 00175 } 00176 --_M_cur; 00177 return *this; 00178 } 00179 00180 _Self 00181 operator--(int) 00182 { 00183 _Self __tmp = *this; 00184 --*this; 00185 return __tmp; 00186 } 00187 00188 _Self& 00189 operator+=(difference_type __n) 00190 { 00191 const difference_type __offset = __n + (_M_cur - _M_first); 00192 if (__offset >= 0 && __offset < difference_type(_S_buffer_size())) 00193 _M_cur += __n; 00194 else 00195 { 00196 const difference_type __node_offset = 00197 __offset > 0 ? __offset / difference_type(_S_buffer_size()) 00198 : -difference_type((-__offset - 1) 00199 / _S_buffer_size()) - 1; 00200 _M_set_node(_M_node + __node_offset); 00201 _M_cur = _M_first + (__offset - __node_offset 00202 * difference_type(_S_buffer_size())); 00203 } 00204 return *this; 00205 } 00206 00207 _Self 00208 operator+(difference_type __n) const 00209 { 00210 _Self __tmp = *this; 00211 return __tmp += __n; 00212 } 00213 00214 _Self& 00215 operator-=(difference_type __n) 00216 { return *this += -__n; } 00217 00218 _Self 00219 operator-(difference_type __n) const 00220 { 00221 _Self __tmp = *this; 00222 return __tmp -= __n; 00223 } 00224 00225 reference 00226 operator[](difference_type __n) const 00227 { return *(*this + __n); } 00228 00229 /** 00230 * Prepares to traverse new_node. Sets everything except 00231 * _M_cur, which should therefore be set by the caller 00232 * immediately afterwards, based on _M_first and _M_last. 00233 */ 00234 void 00235 _M_set_node(_Map_pointer __new_node) 00236 { 00237 _M_node = __new_node; 00238 _M_first = *__new_node; 00239 _M_last = _M_first + difference_type(_S_buffer_size()); 00240 } 00241 }; 00242 00243 // Note: we also provide overloads whose operands are of the same type in 00244 // order to avoid ambiguous overload resolution when std::rel_ops operators 00245 // are in scope (for additional details, see libstdc++/3628) 00246 template<typename _Tp, typename _Ref, typename _Ptr> 00247 inline bool 00248 operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, 00249 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) 00250 { return __x._M_cur == __y._M_cur; } 00251 00252 template<typename _Tp, typename _RefL, typename _PtrL, 00253 typename _RefR, typename _PtrR> 00254 inline bool 00255 operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, 00256 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) 00257 { return __x._M_cur == __y._M_cur; } 00258 00259 template<typename _Tp, typename _Ref, typename _Ptr> 00260 inline bool 00261 operator!=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, 00262 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) 00263 { return !(__x == __y); } 00264 00265 template<typename _Tp, typename _RefL, typename _PtrL, 00266 typename _RefR, typename _PtrR> 00267 inline bool 00268 operator!=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, 00269 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) 00270 { return !(__x == __y); } 00271 00272 template<typename _Tp, typename _Ref, typename _Ptr> 00273 inline bool 00274 operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, 00275 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) 00276 { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur) 00277 : (__x._M_node < __y._M_node); } 00278 00279 template<typename _Tp, typename _RefL, typename _PtrL, 00280 typename _RefR, typename _PtrR> 00281 inline bool 00282 operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, 00283 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) 00284 { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur) 00285 : (__x._M_node < __y._M_node); } 00286 00287 template<typename _Tp, typename _Ref, typename _Ptr> 00288 inline bool 00289 operator>(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, 00290 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) 00291 { return __y < __x; } 00292 00293 template<typename _Tp, typename _RefL, typename _PtrL, 00294 typename _RefR, typename _PtrR> 00295 inline bool 00296 operator>(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, 00297 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) 00298 { return __y < __x; } 00299 00300 template<typename _Tp, typename _Ref, typename _Ptr> 00301 inline bool 00302 operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, 00303 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) 00304 { return !(__y < __x); } 00305 00306 template<typename _Tp, typename _RefL, typename _PtrL, 00307 typename _RefR, typename _PtrR> 00308 inline bool 00309 operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, 00310 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) 00311 { return !(__y < __x); } 00312 00313 template<typename _Tp, typename _Ref, typename _Ptr> 00314 inline bool 00315 operator>=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, 00316 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) 00317 { return !(__x < __y); } 00318 00319 template<typename _Tp, typename _RefL, typename _PtrL, 00320 typename _RefR, typename _PtrR> 00321 inline bool 00322 operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, 00323 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) 00324 { return !(__x < __y); } 00325 00326 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00327 // According to the resolution of DR179 not only the various comparison 00328 // operators but also operator- must accept mixed iterator/const_iterator 00329 // parameters. 00330 template<typename _Tp, typename _Ref, typename _Ptr> 00331 inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type 00332 operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, 00333 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) 00334 { 00335 return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type 00336 (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size()) 00337 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first) 00338 + (__y._M_last - __y._M_cur); 00339 } 00340 00341 template<typename _Tp, typename _RefL, typename _PtrL, 00342 typename _RefR, typename _PtrR> 00343 inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type 00344 operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, 00345 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) 00346 { 00347 return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type 00348 (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size()) 00349 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first) 00350 + (__y._M_last - __y._M_cur); 00351 } 00352 00353 template<typename _Tp, typename _Ref, typename _Ptr> 00354 inline _Deque_iterator<_Tp, _Ref, _Ptr> 00355 operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x) 00356 { return __x + __n; } 00357 00358 template<typename _Tp> 00359 void 00360 fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>&, 00361 const _Deque_iterator<_Tp, _Tp&, _Tp*>&, const _Tp&); 00362 00363 template<typename _Tp> 00364 _Deque_iterator<_Tp, _Tp&, _Tp*> 00365 copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>, 00366 _Deque_iterator<_Tp, const _Tp&, const _Tp*>, 00367 _Deque_iterator<_Tp, _Tp&, _Tp*>); 00368 00369 template<typename _Tp> 00370 inline _Deque_iterator<_Tp, _Tp&, _Tp*> 00371 copy(_Deque_iterator<_Tp, _Tp&, _Tp*> __first, 00372 _Deque_iterator<_Tp, _Tp&, _Tp*> __last, 00373 _Deque_iterator<_Tp, _Tp&, _Tp*> __result) 00374 { return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first), 00375 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last), 00376 __result); } 00377 00378 template<typename _Tp> 00379 _Deque_iterator<_Tp, _Tp&, _Tp*> 00380 copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>, 00381 _Deque_iterator<_Tp, const _Tp&, const _Tp*>, 00382 _Deque_iterator<_Tp, _Tp&, _Tp*>); 00383 00384 template<typename _Tp> 00385 inline _Deque_iterator<_Tp, _Tp&, _Tp*> 00386 copy_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first, 00387 _Deque_iterator<_Tp, _Tp&, _Tp*> __last, 00388 _Deque_iterator<_Tp, _Tp&, _Tp*> __result) 00389 { return std::copy_backward(_Deque_iterator<_Tp, 00390 const _Tp&, const _Tp*>(__first), 00391 _Deque_iterator<_Tp, 00392 const _Tp&, const _Tp*>(__last), 00393 __result); } 00394 00395 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00396 template<typename _Tp> 00397 _Deque_iterator<_Tp, _Tp&, _Tp*> 00398 move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>, 00399 _Deque_iterator<_Tp, const _Tp&, const _Tp*>, 00400 _Deque_iterator<_Tp, _Tp&, _Tp*>); 00401 00402 template<typename _Tp> 00403 inline _Deque_iterator<_Tp, _Tp&, _Tp*> 00404 move(_Deque_iterator<_Tp, _Tp&, _Tp*> __first, 00405 _Deque_iterator<_Tp, _Tp&, _Tp*> __last, 00406 _Deque_iterator<_Tp, _Tp&, _Tp*> __result) 00407 { return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first), 00408 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last), 00409 __result); } 00410 00411 template<typename _Tp> 00412 _Deque_iterator<_Tp, _Tp&, _Tp*> 00413 move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>, 00414 _Deque_iterator<_Tp, const _Tp&, const _Tp*>, 00415 _Deque_iterator<_Tp, _Tp&, _Tp*>); 00416 00417 template<typename _Tp> 00418 inline _Deque_iterator<_Tp, _Tp&, _Tp*> 00419 move_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first, 00420 _Deque_iterator<_Tp, _Tp&, _Tp*> __last, 00421 _Deque_iterator<_Tp, _Tp&, _Tp*> __result) 00422 { return std::move_backward(_Deque_iterator<_Tp, 00423 const _Tp&, const _Tp*>(__first), 00424 _Deque_iterator<_Tp, 00425 const _Tp&, const _Tp*>(__last), 00426 __result); } 00427 #endif 00428 00429 /** 00430 * Deque base class. This class provides the unified face for %deque's 00431 * allocation. This class's constructor and destructor allocate and 00432 * deallocate (but do not initialize) storage. This makes %exception 00433 * safety easier. 00434 * 00435 * Nothing in this class ever constructs or destroys an actual Tp element. 00436 * (Deque handles that itself.) Only/All memory management is performed 00437 * here. 00438 */ 00439 template<typename _Tp, typename _Alloc> 00440 class _Deque_base 00441 { 00442 public: 00443 typedef _Alloc allocator_type; 00444 00445 allocator_type 00446 get_allocator() const _GLIBCXX_NOEXCEPT 00447 { return allocator_type(_M_get_Tp_allocator()); } 00448 00449 typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator; 00450 typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator; 00451 00452 _Deque_base() 00453 : _M_impl() 00454 { _M_initialize_map(0); } 00455 00456 _Deque_base(size_t __num_elements) 00457 : _M_impl() 00458 { _M_initialize_map(__num_elements); } 00459 00460 _Deque_base(const allocator_type& __a, size_t __num_elements) 00461 : _M_impl(__a) 00462 { _M_initialize_map(__num_elements); } 00463 00464 _Deque_base(const allocator_type& __a) 00465 : _M_impl(__a) 00466 { } 00467 00468 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00469 _Deque_base(_Deque_base&& __x) 00470 : _M_impl(std::move(__x._M_get_Tp_allocator())) 00471 { 00472 _M_initialize_map(0); 00473 if (__x._M_impl._M_map) 00474 { 00475 std::swap(this->_M_impl._M_start, __x._M_impl._M_start); 00476 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); 00477 std::swap(this->_M_impl._M_map, __x._M_impl._M_map); 00478 std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size); 00479 } 00480 } 00481 #endif 00482 00483 ~_Deque_base(); 00484 00485 protected: 00486 //This struct encapsulates the implementation of the std::deque 00487 //standard container and at the same time makes use of the EBO 00488 //for empty allocators. 00489 typedef typename _Alloc::template rebind<_Tp*>::other _Map_alloc_type; 00490 00491 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type; 00492 00493 struct _Deque_impl 00494 : public _Tp_alloc_type 00495 { 00496 _Tp** _M_map; 00497 size_t _M_map_size; 00498 iterator _M_start; 00499 iterator _M_finish; 00500 00501 _Deque_impl() 00502 : _Tp_alloc_type(), _M_map(0), _M_map_size(0), 00503 _M_start(), _M_finish() 00504 { } 00505 00506 _Deque_impl(const _Tp_alloc_type& __a) 00507 : _Tp_alloc_type(__a), _M_map(0), _M_map_size(0), 00508 _M_start(), _M_finish() 00509 { } 00510 00511 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00512 _Deque_impl(_Tp_alloc_type&& __a) 00513 : _Tp_alloc_type(std::move(__a)), _M_map(0), _M_map_size(0), 00514 _M_start(), _M_finish() 00515 { } 00516 #endif 00517 }; 00518 00519 _Tp_alloc_type& 00520 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT 00521 { return *static_cast<_Tp_alloc_type*>(&this->_M_impl); } 00522 00523 const _Tp_alloc_type& 00524 _M_get_Tp_allocator() const _GLIBCXX_NOEXCEPT 00525 { return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); } 00526 00527 _Map_alloc_type 00528 _M_get_map_allocator() const _GLIBCXX_NOEXCEPT 00529 { return _Map_alloc_type(_M_get_Tp_allocator()); } 00530 00531 _Tp* 00532 _M_allocate_node() 00533 { 00534 return _M_impl._Tp_alloc_type::allocate(__deque_buf_size(sizeof(_Tp))); 00535 } 00536 00537 void 00538 _M_deallocate_node(_Tp* __p) 00539 { 00540 _M_impl._Tp_alloc_type::deallocate(__p, __deque_buf_size(sizeof(_Tp))); 00541 } 00542 00543 _Tp** 00544 _M_allocate_map(size_t __n) 00545 { return _M_get_map_allocator().allocate(__n); } 00546 00547 void 00548 _M_deallocate_map(_Tp** __p, size_t __n) 00549 { _M_get_map_allocator().deallocate(__p, __n); } 00550 00551 protected: 00552 void _M_initialize_map(size_t); 00553 void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish); 00554 void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish); 00555 enum { _S_initial_map_size = 8 }; 00556 00557 _Deque_impl _M_impl; 00558 }; 00559 00560 template<typename _Tp, typename _Alloc> 00561 _Deque_base<_Tp, _Alloc>:: 00562 ~_Deque_base() 00563 { 00564 if (this->_M_impl._M_map) 00565 { 00566 _M_destroy_nodes(this->_M_impl._M_start._M_node, 00567 this->_M_impl._M_finish._M_node + 1); 00568 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size); 00569 } 00570 } 00571 00572 /** 00573 * @brief Layout storage. 00574 * @param __num_elements The count of T's for which to allocate space 00575 * at first. 00576 * @return Nothing. 00577 * 00578 * The initial underlying memory layout is a bit complicated... 00579 */ 00580 template<typename _Tp, typename _Alloc> 00581 void 00582 _Deque_base<_Tp, _Alloc>:: 00583 _M_initialize_map(size_t __num_elements) 00584 { 00585 const size_t __num_nodes = (__num_elements/ __deque_buf_size(sizeof(_Tp)) 00586 + 1); 00587 00588 this->_M_impl._M_map_size = std::max((size_t) _S_initial_map_size, 00589 size_t(__num_nodes + 2)); 00590 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size); 00591 00592 // For "small" maps (needing less than _M_map_size nodes), allocation 00593 // starts in the middle elements and grows outwards. So nstart may be 00594 // the beginning of _M_map, but for small maps it may be as far in as 00595 // _M_map+3. 00596 00597 _Tp** __nstart = (this->_M_impl._M_map 00598 + (this->_M_impl._M_map_size - __num_nodes) / 2); 00599 _Tp** __nfinish = __nstart + __num_nodes; 00600 00601 __try 00602 { _M_create_nodes(__nstart, __nfinish); } 00603 __catch(...) 00604 { 00605 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size); 00606 this->_M_impl._M_map = 0; 00607 this->_M_impl._M_map_size = 0; 00608 __throw_exception_again; 00609 } 00610 00611 this->_M_impl._M_start._M_set_node(__nstart); 00612 this->_M_impl._M_finish._M_set_node(__nfinish - 1); 00613 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first; 00614 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first 00615 + __num_elements 00616 % __deque_buf_size(sizeof(_Tp))); 00617 } 00618 00619 template<typename _Tp, typename _Alloc> 00620 void 00621 _Deque_base<_Tp, _Alloc>:: 00622 _M_create_nodes(_Tp** __nstart, _Tp** __nfinish) 00623 { 00624 _Tp** __cur; 00625 __try 00626 { 00627 for (__cur = __nstart; __cur < __nfinish; ++__cur) 00628 *__cur = this->_M_allocate_node(); 00629 } 00630 __catch(...) 00631 { 00632 _M_destroy_nodes(__nstart, __cur); 00633 __throw_exception_again; 00634 } 00635 } 00636 00637 template<typename _Tp, typename _Alloc> 00638 void 00639 _Deque_base<_Tp, _Alloc>:: 00640 _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish) 00641 { 00642 for (_Tp** __n = __nstart; __n < __nfinish; ++__n) 00643 _M_deallocate_node(*__n); 00644 } 00645 00646 /** 00647 * @brief A standard container using fixed-size memory allocation and 00648 * constant-time manipulation of elements at either end. 00649 * 00650 * @ingroup sequences 00651 * 00652 * @tparam _Tp Type of element. 00653 * @tparam _Alloc Allocator type, defaults to allocator<_Tp>. 00654 * 00655 * Meets the requirements of a <a href="tables.html#65">container</a>, a 00656 * <a href="tables.html#66">reversible container</a>, and a 00657 * <a href="tables.html#67">sequence</a>, including the 00658 * <a href="tables.html#68">optional sequence requirements</a>. 00659 * 00660 * In previous HP/SGI versions of deque, there was an extra template 00661 * parameter so users could control the node size. This extension turned 00662 * out to violate the C++ standard (it can be detected using template 00663 * template parameters), and it was removed. 00664 * 00665 * Here's how a deque<Tp> manages memory. Each deque has 4 members: 00666 * 00667 * - Tp** _M_map 00668 * - size_t _M_map_size 00669 * - iterator _M_start, _M_finish 00670 * 00671 * map_size is at least 8. %map is an array of map_size 00672 * pointers-to-@a nodes. (The name %map has nothing to do with the 00673 * std::map class, and @b nodes should not be confused with 00674 * std::list's usage of @a node.) 00675 * 00676 * A @a node has no specific type name as such, but it is referred 00677 * to as @a node in this file. It is a simple array-of-Tp. If Tp 00678 * is very large, there will be one Tp element per node (i.e., an 00679 * @a array of one). For non-huge Tp's, node size is inversely 00680 * related to Tp size: the larger the Tp, the fewer Tp's will fit 00681 * in a node. The goal here is to keep the total size of a node 00682 * relatively small and constant over different Tp's, to improve 00683 * allocator efficiency. 00684 * 00685 * Not every pointer in the %map array will point to a node. If 00686 * the initial number of elements in the deque is small, the 00687 * /middle/ %map pointers will be valid, and the ones at the edges 00688 * will be unused. This same situation will arise as the %map 00689 * grows: available %map pointers, if any, will be on the ends. As 00690 * new nodes are created, only a subset of the %map's pointers need 00691 * to be copied @a outward. 00692 * 00693 * Class invariants: 00694 * - For any nonsingular iterator i: 00695 * - i.node points to a member of the %map array. (Yes, you read that 00696 * correctly: i.node does not actually point to a node.) The member of 00697 * the %map array is what actually points to the node. 00698 * - i.first == *(i.node) (This points to the node (first Tp element).) 00699 * - i.last == i.first + node_size 00700 * - i.cur is a pointer in the range [i.first, i.last). NOTE: 00701 * the implication of this is that i.cur is always a dereferenceable 00702 * pointer, even if i is a past-the-end iterator. 00703 * - Start and Finish are always nonsingular iterators. NOTE: this 00704 * means that an empty deque must have one node, a deque with <N 00705 * elements (where N is the node buffer size) must have one node, a 00706 * deque with N through (2N-1) elements must have two nodes, etc. 00707 * - For every node other than start.node and finish.node, every 00708 * element in the node is an initialized object. If start.node == 00709 * finish.node, then [start.cur, finish.cur) are initialized 00710 * objects, and the elements outside that range are uninitialized 00711 * storage. Otherwise, [start.cur, start.last) and [finish.first, 00712 * finish.cur) are initialized objects, and [start.first, start.cur) 00713 * and [finish.cur, finish.last) are uninitialized storage. 00714 * - [%map, %map + map_size) is a valid, non-empty range. 00715 * - [start.node, finish.node] is a valid range contained within 00716 * [%map, %map + map_size). 00717 * - A pointer in the range [%map, %map + map_size) points to an allocated 00718 * node if and only if the pointer is in the range 00719 * [start.node, finish.node]. 00720 * 00721 * Here's the magic: nothing in deque is @b aware of the discontiguous 00722 * storage! 00723 * 00724 * The memory setup and layout occurs in the parent, _Base, and the iterator 00725 * class is entirely responsible for @a leaping from one node to the next. 00726 * All the implementation routines for deque itself work only through the 00727 * start and finish iterators. This keeps the routines simple and sane, 00728 * and we can use other standard algorithms as well. 00729 */ 00730 template<typename _Tp, typename _Alloc = std::allocator<_Tp> > 00731 class deque : protected _Deque_base<_Tp, _Alloc> 00732 { 00733 // concept requirements 00734 typedef typename _Alloc::value_type _Alloc_value_type; 00735 __glibcxx_class_requires(_Tp, _SGIAssignableConcept) 00736 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept) 00737 00738 typedef _Deque_base<_Tp, _Alloc> _Base; 00739 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; 00740 00741 public: 00742 typedef _Tp value_type; 00743 typedef typename _Tp_alloc_type::pointer pointer; 00744 typedef typename _Tp_alloc_type::const_pointer const_pointer; 00745 typedef typename _Tp_alloc_type::reference reference; 00746 typedef typename _Tp_alloc_type::const_reference const_reference; 00747 typedef typename _Base::iterator iterator; 00748 typedef typename _Base::const_iterator const_iterator; 00749 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00750 typedef std::reverse_iterator<iterator> reverse_iterator; 00751 typedef size_t size_type; 00752 typedef ptrdiff_t difference_type; 00753 typedef _Alloc allocator_type; 00754 00755 protected: 00756 typedef pointer* _Map_pointer; 00757 00758 static size_t _S_buffer_size() 00759 { return __deque_buf_size(sizeof(_Tp)); } 00760 00761 // Functions controlling memory layout, and nothing else. 00762 using _Base::_M_initialize_map; 00763 using _Base::_M_create_nodes; 00764 using _Base::_M_destroy_nodes; 00765 using _Base::_M_allocate_node; 00766 using _Base::_M_deallocate_node; 00767 using _Base::_M_allocate_map; 00768 using _Base::_M_deallocate_map; 00769 using _Base::_M_get_Tp_allocator; 00770 00771 /** 00772 * A total of four data members accumulated down the hierarchy. 00773 * May be accessed via _M_impl.* 00774 */ 00775 using _Base::_M_impl; 00776 00777 public: 00778 // [23.2.1.1] construct/copy/destroy 00779 // (assign() and get_allocator() are also listed in this section) 00780 /** 00781 * @brief Default constructor creates no elements. 00782 */ 00783 deque() 00784 : _Base() { } 00785 00786 /** 00787 * @brief Creates a %deque with no elements. 00788 * @param __a An allocator object. 00789 */ 00790 explicit 00791 deque(const allocator_type& __a) 00792 : _Base(__a, 0) { } 00793 00794 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00795 /** 00796 * @brief Creates a %deque with default constructed elements. 00797 * @param __n The number of elements to initially create. 00798 * 00799 * This constructor fills the %deque with @a n default 00800 * constructed elements. 00801 */ 00802 explicit 00803 deque(size_type __n) 00804 : _Base(__n) 00805 { _M_default_initialize(); } 00806 00807 /** 00808 * @brief Creates a %deque with copies of an exemplar element. 00809 * @param __n The number of elements to initially create. 00810 * @param __value An element to copy. 00811 * @param __a An allocator. 00812 * 00813 * This constructor fills the %deque with @a __n copies of @a __value. 00814 */ 00815 deque(size_type __n, const value_type& __value, 00816 const allocator_type& __a = allocator_type()) 00817 : _Base(__a, __n) 00818 { _M_fill_initialize(__value); } 00819 #else 00820 /** 00821 * @brief Creates a %deque with copies of an exemplar element. 00822 * @param __n The number of elements to initially create. 00823 * @param __value An element to copy. 00824 * @param __a An allocator. 00825 * 00826 * This constructor fills the %deque with @a __n copies of @a __value. 00827 */ 00828 explicit 00829 deque(size_type __n, const value_type& __value = value_type(), 00830 const allocator_type& __a = allocator_type()) 00831 : _Base(__a, __n) 00832 { _M_fill_initialize(__value); } 00833 #endif 00834 00835 /** 00836 * @brief %Deque copy constructor. 00837 * @param __x A %deque of identical element and allocator types. 00838 * 00839 * The newly-created %deque uses a copy of the allocation object used 00840 * by @a __x. 00841 */ 00842 deque(const deque& __x) 00843 : _Base(__x._M_get_Tp_allocator(), __x.size()) 00844 { std::__uninitialized_copy_a(__x.begin(), __x.end(), 00845 this->_M_impl._M_start, 00846 _M_get_Tp_allocator()); } 00847 00848 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00849 /** 00850 * @brief %Deque move constructor. 00851 * @param __x A %deque of identical element and allocator types. 00852 * 00853 * The newly-created %deque contains the exact contents of @a __x. 00854 * The contents of @a __x are a valid, but unspecified %deque. 00855 */ 00856 deque(deque&& __x) 00857 : _Base(std::move(__x)) { } 00858 00859 /** 00860 * @brief Builds a %deque from an initializer list. 00861 * @param __l An initializer_list. 00862 * @param __a An allocator object. 00863 * 00864 * Create a %deque consisting of copies of the elements in the 00865 * initializer_list @a __l. 00866 * 00867 * This will call the element type's copy constructor N times 00868 * (where N is __l.size()) and do no memory reallocation. 00869 */ 00870 deque(initializer_list<value_type> __l, 00871 const allocator_type& __a = allocator_type()) 00872 : _Base(__a) 00873 { 00874 _M_range_initialize(__l.begin(), __l.end(), 00875 random_access_iterator_tag()); 00876 } 00877 #endif 00878 00879 /** 00880 * @brief Builds a %deque from a range. 00881 * @param __first An input iterator. 00882 * @param __last An input iterator. 00883 * @param __a An allocator object. 00884 * 00885 * Create a %deque consisting of copies of the elements from [__first, 00886 * __last). 00887 * 00888 * If the iterators are forward, bidirectional, or random-access, then 00889 * this will call the elements' copy constructor N times (where N is 00890 * distance(__first,__last)) and do no memory reallocation. But if only 00891 * input iterators are used, then this will do at most 2N calls to the 00892 * copy constructor, and logN memory reallocations. 00893 */ 00894 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00895 template<typename _InputIterator, 00896 typename = std::_RequireInputIter<_InputIterator>> 00897 deque(_InputIterator __first, _InputIterator __last, 00898 const allocator_type& __a = allocator_type()) 00899 : _Base(__a) 00900 { _M_initialize_dispatch(__first, __last, __false_type()); } 00901 #else 00902 template<typename _InputIterator> 00903 deque(_InputIterator __first, _InputIterator __last, 00904 const allocator_type& __a = allocator_type()) 00905 : _Base(__a) 00906 { 00907 // Check whether it's an integral type. If so, it's not an iterator. 00908 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 00909 _M_initialize_dispatch(__first, __last, _Integral()); 00910 } 00911 #endif 00912 00913 /** 00914 * The dtor only erases the elements, and note that if the elements 00915 * themselves are pointers, the pointed-to memory is not touched in any 00916 * way. Managing the pointer is the user's responsibility. 00917 */ 00918 ~deque() _GLIBCXX_NOEXCEPT 00919 { _M_destroy_data(begin(), end(), _M_get_Tp_allocator()); } 00920 00921 /** 00922 * @brief %Deque assignment operator. 00923 * @param __x A %deque of identical element and allocator types. 00924 * 00925 * All the elements of @a x are copied, but unlike the copy constructor, 00926 * the allocator object is not copied. 00927 */ 00928 deque& 00929 operator=(const deque& __x); 00930 00931 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00932 /** 00933 * @brief %Deque move assignment operator. 00934 * @param __x A %deque of identical element and allocator types. 00935 * 00936 * The contents of @a __x are moved into this deque (without copying). 00937 * @a __x is a valid, but unspecified %deque. 00938 */ 00939 deque& 00940 operator=(deque&& __x) 00941 { 00942 // NB: DR 1204. 00943 // NB: DR 675. 00944 this->clear(); 00945 this->swap(__x); 00946 return *this; 00947 } 00948 00949 /** 00950 * @brief Assigns an initializer list to a %deque. 00951 * @param __l An initializer_list. 00952 * 00953 * This function fills a %deque with copies of the elements in the 00954 * initializer_list @a __l. 00955 * 00956 * Note that the assignment completely changes the %deque and that the 00957 * resulting %deque's size is the same as the number of elements 00958 * assigned. Old data may be lost. 00959 */ 00960 deque& 00961 operator=(initializer_list<value_type> __l) 00962 { 00963 this->assign(__l.begin(), __l.end()); 00964 return *this; 00965 } 00966 #endif 00967 00968 /** 00969 * @brief Assigns a given value to a %deque. 00970 * @param __n Number of elements to be assigned. 00971 * @param __val Value to be assigned. 00972 * 00973 * This function fills a %deque with @a n copies of the given 00974 * value. Note that the assignment completely changes the 00975 * %deque and that the resulting %deque's size is the same as 00976 * the number of elements assigned. Old data may be lost. 00977 */ 00978 void 00979 assign(size_type __n, const value_type& __val) 00980 { _M_fill_assign(__n, __val); } 00981 00982 /** 00983 * @brief Assigns a range to a %deque. 00984 * @param __first An input iterator. 00985 * @param __last An input iterator. 00986 * 00987 * This function fills a %deque with copies of the elements in the 00988 * range [__first,__last). 00989 * 00990 * Note that the assignment completely changes the %deque and that the 00991 * resulting %deque's size is the same as the number of elements 00992 * assigned. Old data may be lost. 00993 */ 00994 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00995 template<typename _InputIterator, 00996 typename = std::_RequireInputIter<_InputIterator>> 00997 void 00998 assign(_InputIterator __first, _InputIterator __last) 00999 { _M_assign_dispatch(__first, __last, __false_type()); } 01000 #else 01001 template<typename _InputIterator> 01002 void 01003 assign(_InputIterator __first, _InputIterator __last) 01004 { 01005 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 01006 _M_assign_dispatch(__first, __last, _Integral()); 01007 } 01008 #endif 01009 01010 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01011 /** 01012 * @brief Assigns an initializer list to a %deque. 01013 * @param __l An initializer_list. 01014 * 01015 * This function fills a %deque with copies of the elements in the 01016 * initializer_list @a __l. 01017 * 01018 * Note that the assignment completely changes the %deque and that the 01019 * resulting %deque's size is the same as the number of elements 01020 * assigned. Old data may be lost. 01021 */ 01022 void 01023 assign(initializer_list<value_type> __l) 01024 { this->assign(__l.begin(), __l.end()); } 01025 #endif 01026 01027 /// Get a copy of the memory allocation object. 01028 allocator_type 01029 get_allocator() const _GLIBCXX_NOEXCEPT 01030 { return _Base::get_allocator(); } 01031 01032 // iterators 01033 /** 01034 * Returns a read/write iterator that points to the first element in the 01035 * %deque. Iteration is done in ordinary element order. 01036 */ 01037 iterator 01038 begin() _GLIBCXX_NOEXCEPT 01039 { return this->_M_impl._M_start; } 01040 01041 /** 01042 * Returns a read-only (constant) iterator that points to the first 01043 * element in the %deque. Iteration is done in ordinary element order. 01044 */ 01045 const_iterator 01046 begin() const _GLIBCXX_NOEXCEPT 01047 { return this->_M_impl._M_start; } 01048 01049 /** 01050 * Returns a read/write iterator that points one past the last 01051 * element in the %deque. Iteration is done in ordinary 01052 * element order. 01053 */ 01054 iterator 01055 end() _GLIBCXX_NOEXCEPT 01056 { return this->_M_impl._M_finish; } 01057 01058 /** 01059 * Returns a read-only (constant) iterator that points one past 01060 * the last element in the %deque. Iteration is done in 01061 * ordinary element order. 01062 */ 01063 const_iterator 01064 end() const _GLIBCXX_NOEXCEPT 01065 { return this->_M_impl._M_finish; } 01066 01067 /** 01068 * Returns a read/write reverse iterator that points to the 01069 * last element in the %deque. Iteration is done in reverse 01070 * element order. 01071 */ 01072 reverse_iterator 01073 rbegin() _GLIBCXX_NOEXCEPT 01074 { return reverse_iterator(this->_M_impl._M_finish); } 01075 01076 /** 01077 * Returns a read-only (constant) reverse iterator that points 01078 * to the last element in the %deque. Iteration is done in 01079 * reverse element order. 01080 */ 01081 const_reverse_iterator 01082 rbegin() const _GLIBCXX_NOEXCEPT 01083 { return const_reverse_iterator(this->_M_impl._M_finish); } 01084 01085 /** 01086 * Returns a read/write reverse iterator that points to one 01087 * before the first element in the %deque. Iteration is done 01088 * in reverse element order. 01089 */ 01090 reverse_iterator 01091 rend() _GLIBCXX_NOEXCEPT 01092 { return reverse_iterator(this->_M_impl._M_start); } 01093 01094 /** 01095 * Returns a read-only (constant) reverse iterator that points 01096 * to one before the first element in the %deque. Iteration is 01097 * done in reverse element order. 01098 */ 01099 const_reverse_iterator 01100 rend() const _GLIBCXX_NOEXCEPT 01101 { return const_reverse_iterator(this->_M_impl._M_start); } 01102 01103 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01104 /** 01105 * Returns a read-only (constant) iterator that points to the first 01106 * element in the %deque. Iteration is done in ordinary element order. 01107 */ 01108 const_iterator 01109 cbegin() const noexcept 01110 { return this->_M_impl._M_start; } 01111 01112 /** 01113 * Returns a read-only (constant) iterator that points one past 01114 * the last element in the %deque. Iteration is done in 01115 * ordinary element order. 01116 */ 01117 const_iterator 01118 cend() const noexcept 01119 { return this->_M_impl._M_finish; } 01120 01121 /** 01122 * Returns a read-only (constant) reverse iterator that points 01123 * to the last element in the %deque. Iteration is done in 01124 * reverse element order. 01125 */ 01126 const_reverse_iterator 01127 crbegin() const noexcept 01128 { return const_reverse_iterator(this->_M_impl._M_finish); } 01129 01130 /** 01131 * Returns a read-only (constant) reverse iterator that points 01132 * to one before the first element in the %deque. Iteration is 01133 * done in reverse element order. 01134 */ 01135 const_reverse_iterator 01136 crend() const noexcept 01137 { return const_reverse_iterator(this->_M_impl._M_start); } 01138 #endif 01139 01140 // [23.2.1.2] capacity 01141 /** Returns the number of elements in the %deque. */ 01142 size_type 01143 size() const _GLIBCXX_NOEXCEPT 01144 { return this->_M_impl._M_finish - this->_M_impl._M_start; } 01145 01146 /** Returns the size() of the largest possible %deque. */ 01147 size_type 01148 max_size() const _GLIBCXX_NOEXCEPT 01149 { return _M_get_Tp_allocator().max_size(); } 01150 01151 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01152 /** 01153 * @brief Resizes the %deque to the specified number of elements. 01154 * @param __new_size Number of elements the %deque should contain. 01155 * 01156 * This function will %resize the %deque to the specified 01157 * number of elements. If the number is smaller than the 01158 * %deque's current size the %deque is truncated, otherwise 01159 * default constructed elements are appended. 01160 */ 01161 void 01162 resize(size_type __new_size) 01163 { 01164 const size_type __len = size(); 01165 if (__new_size > __len) 01166 _M_default_append(__new_size - __len); 01167 else if (__new_size < __len) 01168 _M_erase_at_end(this->_M_impl._M_start 01169 + difference_type(__new_size)); 01170 } 01171 01172 /** 01173 * @brief Resizes the %deque to the specified number of elements. 01174 * @param __new_size Number of elements the %deque should contain. 01175 * @param __x Data with which new elements should be populated. 01176 * 01177 * This function will %resize the %deque to the specified 01178 * number of elements. If the number is smaller than the 01179 * %deque's current size the %deque is truncated, otherwise the 01180 * %deque is extended and new elements are populated with given 01181 * data. 01182 */ 01183 void 01184 resize(size_type __new_size, const value_type& __x) 01185 { 01186 const size_type __len = size(); 01187 if (__new_size > __len) 01188 insert(this->_M_impl._M_finish, __new_size - __len, __x); 01189 else if (__new_size < __len) 01190 _M_erase_at_end(this->_M_impl._M_start 01191 + difference_type(__new_size)); 01192 } 01193 #else 01194 /** 01195 * @brief Resizes the %deque to the specified number of elements. 01196 * @param __new_size Number of elements the %deque should contain. 01197 * @param __x Data with which new elements should be populated. 01198 * 01199 * This function will %resize the %deque to the specified 01200 * number of elements. If the number is smaller than the 01201 * %deque's current size the %deque is truncated, otherwise the 01202 * %deque is extended and new elements are populated with given 01203 * data. 01204 */ 01205 void 01206 resize(size_type __new_size, value_type __x = value_type()) 01207 { 01208 const size_type __len = size(); 01209 if (__new_size > __len) 01210 insert(this->_M_impl._M_finish, __new_size - __len, __x); 01211 else if (__new_size < __len) 01212 _M_erase_at_end(this->_M_impl._M_start 01213 + difference_type(__new_size)); 01214 } 01215 #endif 01216 01217 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01218 /** A non-binding request to reduce memory use. */ 01219 void 01220 shrink_to_fit() 01221 { _M_shrink_to_fit(); } 01222 #endif 01223 01224 /** 01225 * Returns true if the %deque is empty. (Thus begin() would 01226 * equal end().) 01227 */ 01228 bool 01229 empty() const _GLIBCXX_NOEXCEPT 01230 { return this->_M_impl._M_finish == this->_M_impl._M_start; } 01231 01232 // element access 01233 /** 01234 * @brief Subscript access to the data contained in the %deque. 01235 * @param __n The index of the element for which data should be 01236 * accessed. 01237 * @return Read/write reference to data. 01238 * 01239 * This operator allows for easy, array-style, data access. 01240 * Note that data access with this operator is unchecked and 01241 * out_of_range lookups are not defined. (For checked lookups 01242 * see at().) 01243 */ 01244 reference 01245 operator[](size_type __n) 01246 { return this->_M_impl._M_start[difference_type(__n)]; } 01247 01248 /** 01249 * @brief Subscript access to the data contained in the %deque. 01250 * @param __n The index of the element for which data should be 01251 * accessed. 01252 * @return Read-only (constant) reference to data. 01253 * 01254 * This operator allows for easy, array-style, data access. 01255 * Note that data access with this operator is unchecked and 01256 * out_of_range lookups are not defined. (For checked lookups 01257 * see at().) 01258 */ 01259 const_reference 01260 operator[](size_type __n) const 01261 { return this->_M_impl._M_start[difference_type(__n)]; } 01262 01263 protected: 01264 /// Safety check used only from at(). 01265 void 01266 _M_range_check(size_type __n) const 01267 { 01268 if (__n >= this->size()) 01269 __throw_out_of_range(__N("deque::_M_range_check")); 01270 } 01271 01272 public: 01273 /** 01274 * @brief Provides access to the data contained in the %deque. 01275 * @param __n The index of the element for which data should be 01276 * accessed. 01277 * @return Read/write reference to data. 01278 * @throw std::out_of_range If @a __n is an invalid index. 01279 * 01280 * This function provides for safer data access. The parameter 01281 * is first checked that it is in the range of the deque. The 01282 * function throws out_of_range if the check fails. 01283 */ 01284 reference 01285 at(size_type __n) 01286 { 01287 _M_range_check(__n); 01288 return (*this)[__n]; 01289 } 01290 01291 /** 01292 * @brief Provides access to the data contained in the %deque. 01293 * @param __n The index of the element for which data should be 01294 * accessed. 01295 * @return Read-only (constant) reference to data. 01296 * @throw std::out_of_range If @a __n is an invalid index. 01297 * 01298 * This function provides for safer data access. The parameter is first 01299 * checked that it is in the range of the deque. The function throws 01300 * out_of_range if the check fails. 01301 */ 01302 const_reference 01303 at(size_type __n) const 01304 { 01305 _M_range_check(__n); 01306 return (*this)[__n]; 01307 } 01308 01309 /** 01310 * Returns a read/write reference to the data at the first 01311 * element of the %deque. 01312 */ 01313 reference 01314 front() 01315 { return *begin(); } 01316 01317 /** 01318 * Returns a read-only (constant) reference to the data at the first 01319 * element of the %deque. 01320 */ 01321 const_reference 01322 front() const 01323 { return *begin(); } 01324 01325 /** 01326 * Returns a read/write reference to the data at the last element of the 01327 * %deque. 01328 */ 01329 reference 01330 back() 01331 { 01332 iterator __tmp = end(); 01333 --__tmp; 01334 return *__tmp; 01335 } 01336 01337 /** 01338 * Returns a read-only (constant) reference to the data at the last 01339 * element of the %deque. 01340 */ 01341 const_reference 01342 back() const 01343 { 01344 const_iterator __tmp = end(); 01345 --__tmp; 01346 return *__tmp; 01347 } 01348 01349 // [23.2.1.2] modifiers 01350 /** 01351 * @brief Add data to the front of the %deque. 01352 * @param __x Data to be added. 01353 * 01354 * This is a typical stack operation. The function creates an 01355 * element at the front of the %deque and assigns the given 01356 * data to it. Due to the nature of a %deque this operation 01357 * can be done in constant time. 01358 */ 01359 void 01360 push_front(const value_type& __x) 01361 { 01362 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first) 01363 { 01364 this->_M_impl.construct(this->_M_impl._M_start._M_cur - 1, __x); 01365 --this->_M_impl._M_start._M_cur; 01366 } 01367 else 01368 _M_push_front_aux(__x); 01369 } 01370 01371 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01372 void 01373 push_front(value_type&& __x) 01374 { emplace_front(std::move(__x)); } 01375 01376 template<typename... _Args> 01377 void 01378 emplace_front(_Args&&... __args); 01379 #endif 01380 01381 /** 01382 * @brief Add data to the end of the %deque. 01383 * @param __x Data to be added. 01384 * 01385 * This is a typical stack operation. The function creates an 01386 * element at the end of the %deque and assigns the given data 01387 * to it. Due to the nature of a %deque this operation can be 01388 * done in constant time. 01389 */ 01390 void 01391 push_back(const value_type& __x) 01392 { 01393 if (this->_M_impl._M_finish._M_cur 01394 != this->_M_impl._M_finish._M_last - 1) 01395 { 01396 this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __x); 01397 ++this->_M_impl._M_finish._M_cur; 01398 } 01399 else 01400 _M_push_back_aux(__x); 01401 } 01402 01403 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01404 void 01405 push_back(value_type&& __x) 01406 { emplace_back(std::move(__x)); } 01407 01408 template<typename... _Args> 01409 void 01410 emplace_back(_Args&&... __args); 01411 #endif 01412 01413 /** 01414 * @brief Removes first element. 01415 * 01416 * This is a typical stack operation. It shrinks the %deque by one. 01417 * 01418 * Note that no data is returned, and if the first element's data is 01419 * needed, it should be retrieved before pop_front() is called. 01420 */ 01421 void 01422 pop_front() 01423 { 01424 if (this->_M_impl._M_start._M_cur 01425 != this->_M_impl._M_start._M_last - 1) 01426 { 01427 this->_M_impl.destroy(this->_M_impl._M_start._M_cur); 01428 ++this->_M_impl._M_start._M_cur; 01429 } 01430 else 01431 _M_pop_front_aux(); 01432 } 01433 01434 /** 01435 * @brief Removes last element. 01436 * 01437 * This is a typical stack operation. It shrinks the %deque by one. 01438 * 01439 * Note that no data is returned, and if the last element's data is 01440 * needed, it should be retrieved before pop_back() is called. 01441 */ 01442 void 01443 pop_back() 01444 { 01445 if (this->_M_impl._M_finish._M_cur 01446 != this->_M_impl._M_finish._M_first) 01447 { 01448 --this->_M_impl._M_finish._M_cur; 01449 this->_M_impl.destroy(this->_M_impl._M_finish._M_cur); 01450 } 01451 else 01452 _M_pop_back_aux(); 01453 } 01454 01455 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01456 /** 01457 * @brief Inserts an object in %deque before specified iterator. 01458 * @param __position An iterator into the %deque. 01459 * @param __args Arguments. 01460 * @return An iterator that points to the inserted data. 01461 * 01462 * This function will insert an object of type T constructed 01463 * with T(std::forward<Args>(args)...) before the specified location. 01464 */ 01465 template<typename... _Args> 01466 iterator 01467 emplace(iterator __position, _Args&&... __args); 01468 #endif 01469 01470 /** 01471 * @brief Inserts given value into %deque before specified iterator. 01472 * @param __position An iterator into the %deque. 01473 * @param __x Data to be inserted. 01474 * @return An iterator that points to the inserted data. 01475 * 01476 * This function will insert a copy of the given value before the 01477 * specified location. 01478 */ 01479 iterator 01480 insert(iterator __position, const value_type& __x); 01481 01482 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01483 /** 01484 * @brief Inserts given rvalue into %deque before specified iterator. 01485 * @param __position An iterator into the %deque. 01486 * @param __x Data to be inserted. 01487 * @return An iterator that points to the inserted data. 01488 * 01489 * This function will insert a copy of the given rvalue before the 01490 * specified location. 01491 */ 01492 iterator 01493 insert(iterator __position, value_type&& __x) 01494 { return emplace(__position, std::move(__x)); } 01495 01496 /** 01497 * @brief Inserts an initializer list into the %deque. 01498 * @param __p An iterator into the %deque. 01499 * @param __l An initializer_list. 01500 * 01501 * This function will insert copies of the data in the 01502 * initializer_list @a __l into the %deque before the location 01503 * specified by @a __p. This is known as <em>list insert</em>. 01504 */ 01505 void 01506 insert(iterator __p, initializer_list<value_type> __l) 01507 { this->insert(__p, __l.begin(), __l.end()); } 01508 #endif 01509 01510 /** 01511 * @brief Inserts a number of copies of given data into the %deque. 01512 * @param __position An iterator into the %deque. 01513 * @param __n Number of elements to be inserted. 01514 * @param __x Data to be inserted. 01515 * 01516 * This function will insert a specified number of copies of the given 01517 * data before the location specified by @a __position. 01518 */ 01519 void 01520 insert(iterator __position, size_type __n, const value_type& __x) 01521 { _M_fill_insert(__position, __n, __x); } 01522 01523 /** 01524 * @brief Inserts a range into the %deque. 01525 * @param __position An iterator into the %deque. 01526 * @param __first An input iterator. 01527 * @param __last An input iterator. 01528 * 01529 * This function will insert copies of the data in the range 01530 * [__first,__last) into the %deque before the location specified 01531 * by @a __position. This is known as <em>range insert</em>. 01532 */ 01533 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01534 template<typename _InputIterator, 01535 typename = std::_RequireInputIter<_InputIterator>> 01536 void 01537 insert(iterator __position, _InputIterator __first, 01538 _InputIterator __last) 01539 { _M_insert_dispatch(__position, __first, __last, __false_type()); } 01540 #else 01541 template<typename _InputIterator> 01542 void 01543 insert(iterator __position, _InputIterator __first, 01544 _InputIterator __last) 01545 { 01546 // Check whether it's an integral type. If so, it's not an iterator. 01547 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 01548 _M_insert_dispatch(__position, __first, __last, _Integral()); 01549 } 01550 #endif 01551 01552 /** 01553 * @brief Remove element at given position. 01554 * @param __position Iterator pointing to element to be erased. 01555 * @return An iterator pointing to the next element (or end()). 01556 * 01557 * This function will erase the element at the given position and thus 01558 * shorten the %deque by one. 01559 * 01560 * The user is cautioned that 01561 * this function only erases the element, and that if the element is 01562 * itself a pointer, the pointed-to memory is not touched in any way. 01563 * Managing the pointer is the user's responsibility. 01564 */ 01565 iterator 01566 erase(iterator __position); 01567 01568 /** 01569 * @brief Remove a range of elements. 01570 * @param __first Iterator pointing to the first element to be erased. 01571 * @param __last Iterator pointing to one past the last element to be 01572 * erased. 01573 * @return An iterator pointing to the element pointed to by @a last 01574 * prior to erasing (or end()). 01575 * 01576 * This function will erase the elements in the range 01577 * [__first,__last) and shorten the %deque accordingly. 01578 * 01579 * The user is cautioned that 01580 * this function only erases the elements, and that if the elements 01581 * themselves are pointers, the pointed-to memory is not touched in any 01582 * way. Managing the pointer is the user's responsibility. 01583 */ 01584 iterator 01585 erase(iterator __first, iterator __last); 01586 01587 /** 01588 * @brief Swaps data with another %deque. 01589 * @param __x A %deque of the same element and allocator types. 01590 * 01591 * This exchanges the elements between two deques in constant time. 01592 * (Four pointers, so it should be quite fast.) 01593 * Note that the global std::swap() function is specialized such that 01594 * std::swap(d1,d2) will feed to this function. 01595 */ 01596 void 01597 swap(deque& __x) 01598 { 01599 std::swap(this->_M_impl._M_start, __x._M_impl._M_start); 01600 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); 01601 std::swap(this->_M_impl._M_map, __x._M_impl._M_map); 01602 std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size); 01603 01604 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01605 // 431. Swapping containers with unequal allocators. 01606 std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(), 01607 __x._M_get_Tp_allocator()); 01608 } 01609 01610 /** 01611 * Erases all the elements. Note that this function only erases the 01612 * elements, and that if the elements themselves are pointers, the 01613 * pointed-to memory is not touched in any way. Managing the pointer is 01614 * the user's responsibility. 01615 */ 01616 void 01617 clear() _GLIBCXX_NOEXCEPT 01618 { _M_erase_at_end(begin()); } 01619 01620 protected: 01621 // Internal constructor functions follow. 01622 01623 // called by the range constructor to implement [23.1.1]/9 01624 01625 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01626 // 438. Ambiguity in the "do the right thing" clause 01627 template<typename _Integer> 01628 void 01629 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) 01630 { 01631 _M_initialize_map(static_cast<size_type>(__n)); 01632 _M_fill_initialize(__x); 01633 } 01634 01635 // called by the range constructor to implement [23.1.1]/9 01636 template<typename _InputIterator> 01637 void 01638 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, 01639 __false_type) 01640 { 01641 typedef typename std::iterator_traits<_InputIterator>:: 01642 iterator_category _IterCategory; 01643 _M_range_initialize(__first, __last, _IterCategory()); 01644 } 01645 01646 // called by the second initialize_dispatch above 01647 //@{ 01648 /** 01649 * @brief Fills the deque with whatever is in [first,last). 01650 * @param __first An input iterator. 01651 * @param __last An input iterator. 01652 * @return Nothing. 01653 * 01654 * If the iterators are actually forward iterators (or better), then the 01655 * memory layout can be done all at once. Else we move forward using 01656 * push_back on each value from the iterator. 01657 */ 01658 template<typename _InputIterator> 01659 void 01660 _M_range_initialize(_InputIterator __first, _InputIterator __last, 01661 std::input_iterator_tag); 01662 01663 // called by the second initialize_dispatch above 01664 template<typename _ForwardIterator> 01665 void 01666 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last, 01667 std::forward_iterator_tag); 01668 //@} 01669 01670 /** 01671 * @brief Fills the %deque with copies of value. 01672 * @param __value Initial value. 01673 * @return Nothing. 01674 * @pre _M_start and _M_finish have already been initialized, 01675 * but none of the %deque's elements have yet been constructed. 01676 * 01677 * This function is called only when the user provides an explicit size 01678 * (with or without an explicit exemplar value). 01679 */ 01680 void 01681 _M_fill_initialize(const value_type& __value); 01682 01683 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01684 // called by deque(n). 01685 void 01686 _M_default_initialize(); 01687 #endif 01688 01689 // Internal assign functions follow. The *_aux functions do the actual 01690 // assignment work for the range versions. 01691 01692 // called by the range assign to implement [23.1.1]/9 01693 01694 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01695 // 438. Ambiguity in the "do the right thing" clause 01696 template<typename _Integer> 01697 void 01698 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) 01699 { _M_fill_assign(__n, __val); } 01700 01701 // called by the range assign to implement [23.1.1]/9 01702 template<typename _InputIterator> 01703 void 01704 _M_assign_dispatch(_InputIterator __first, _InputIterator __last, 01705 __false_type) 01706 { 01707 typedef typename std::iterator_traits<_InputIterator>:: 01708 iterator_category _IterCategory; 01709 _M_assign_aux(__first, __last, _IterCategory()); 01710 } 01711 01712 // called by the second assign_dispatch above 01713 template<typename _InputIterator> 01714 void 01715 _M_assign_aux(_InputIterator __first, _InputIterator __last, 01716 std::input_iterator_tag); 01717 01718 // called by the second assign_dispatch above 01719 template<typename _ForwardIterator> 01720 void 01721 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, 01722 std::forward_iterator_tag) 01723 { 01724 const size_type __len = std::distance(__first, __last); 01725 if (__len > size()) 01726 { 01727 _ForwardIterator __mid = __first; 01728 std::advance(__mid, size()); 01729 std::copy(__first, __mid, begin()); 01730 insert(end(), __mid, __last); 01731 } 01732 else 01733 _M_erase_at_end(std::copy(__first, __last, begin())); 01734 } 01735 01736 // Called by assign(n,t), and the range assign when it turns out 01737 // to be the same thing. 01738 void 01739 _M_fill_assign(size_type __n, const value_type& __val) 01740 { 01741 if (__n > size()) 01742 { 01743 std::fill(begin(), end(), __val); 01744 insert(end(), __n - size(), __val); 01745 } 01746 else 01747 { 01748 _M_erase_at_end(begin() + difference_type(__n)); 01749 std::fill(begin(), end(), __val); 01750 } 01751 } 01752 01753 //@{ 01754 /// Helper functions for push_* and pop_*. 01755 #ifndef __GXX_EXPERIMENTAL_CXX0X__ 01756 void _M_push_back_aux(const value_type&); 01757 01758 void _M_push_front_aux(const value_type&); 01759 #else 01760 template<typename... _Args> 01761 void _M_push_back_aux(_Args&&... __args); 01762 01763 template<typename... _Args> 01764 void _M_push_front_aux(_Args&&... __args); 01765 #endif 01766 01767 void _M_pop_back_aux(); 01768 01769 void _M_pop_front_aux(); 01770 //@} 01771 01772 // Internal insert functions follow. The *_aux functions do the actual 01773 // insertion work when all shortcuts fail. 01774 01775 // called by the range insert to implement [23.1.1]/9 01776 01777 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01778 // 438. Ambiguity in the "do the right thing" clause 01779 template<typename _Integer> 01780 void 01781 _M_insert_dispatch(iterator __pos, 01782 _Integer __n, _Integer __x, __true_type) 01783 { _M_fill_insert(__pos, __n, __x); } 01784 01785 // called by the range insert to implement [23.1.1]/9 01786 template<typename _InputIterator> 01787 void 01788 _M_insert_dispatch(iterator __pos, 01789 _InputIterator __first, _InputIterator __last, 01790 __false_type) 01791 { 01792 typedef typename std::iterator_traits<_InputIterator>:: 01793 iterator_category _IterCategory; 01794 _M_range_insert_aux(__pos, __first, __last, _IterCategory()); 01795 } 01796 01797 // called by the second insert_dispatch above 01798 template<typename _InputIterator> 01799 void 01800 _M_range_insert_aux(iterator __pos, _InputIterator __first, 01801 _InputIterator __last, std::input_iterator_tag); 01802 01803 // called by the second insert_dispatch above 01804 template<typename _ForwardIterator> 01805 void 01806 _M_range_insert_aux(iterator __pos, _ForwardIterator __first, 01807 _ForwardIterator __last, std::forward_iterator_tag); 01808 01809 // Called by insert(p,n,x), and the range insert when it turns out to be 01810 // the same thing. Can use fill functions in optimal situations, 01811 // otherwise passes off to insert_aux(p,n,x). 01812 void 01813 _M_fill_insert(iterator __pos, size_type __n, const value_type& __x); 01814 01815 // called by insert(p,x) 01816 #ifndef __GXX_EXPERIMENTAL_CXX0X__ 01817 iterator 01818 _M_insert_aux(iterator __pos, const value_type& __x); 01819 #else 01820 template<typename... _Args> 01821 iterator 01822 _M_insert_aux(iterator __pos, _Args&&... __args); 01823 #endif 01824 01825 // called by insert(p,n,x) via fill_insert 01826 void 01827 _M_insert_aux(iterator __pos, size_type __n, const value_type& __x); 01828 01829 // called by range_insert_aux for forward iterators 01830 template<typename _ForwardIterator> 01831 void 01832 _M_insert_aux(iterator __pos, 01833 _ForwardIterator __first, _ForwardIterator __last, 01834 size_type __n); 01835 01836 01837 // Internal erase functions follow. 01838 01839 void 01840 _M_destroy_data_aux(iterator __first, iterator __last); 01841 01842 // Called by ~deque(). 01843 // NB: Doesn't deallocate the nodes. 01844 template<typename _Alloc1> 01845 void 01846 _M_destroy_data(iterator __first, iterator __last, const _Alloc1&) 01847 { _M_destroy_data_aux(__first, __last); } 01848 01849 void 01850 _M_destroy_data(iterator __first, iterator __last, 01851 const std::allocator<_Tp>&) 01852 { 01853 if (!__has_trivial_destructor(value_type)) 01854 _M_destroy_data_aux(__first, __last); 01855 } 01856 01857 // Called by erase(q1, q2). 01858 void 01859 _M_erase_at_begin(iterator __pos) 01860 { 01861 _M_destroy_data(begin(), __pos, _M_get_Tp_allocator()); 01862 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node); 01863 this->_M_impl._M_start = __pos; 01864 } 01865 01866 // Called by erase(q1, q2), resize(), clear(), _M_assign_aux, 01867 // _M_fill_assign, operator=. 01868 void 01869 _M_erase_at_end(iterator __pos) 01870 { 01871 _M_destroy_data(__pos, end(), _M_get_Tp_allocator()); 01872 _M_destroy_nodes(__pos._M_node + 1, 01873 this->_M_impl._M_finish._M_node + 1); 01874 this->_M_impl._M_finish = __pos; 01875 } 01876 01877 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 01878 // Called by resize(sz). 01879 void 01880 _M_default_append(size_type __n); 01881 01882 bool 01883 _M_shrink_to_fit(); 01884 #endif 01885 01886 //@{ 01887 /// Memory-handling helpers for the previous internal insert functions. 01888 iterator 01889 _M_reserve_elements_at_front(size_type __n) 01890 { 01891 const size_type __vacancies = this->_M_impl._M_start._M_cur 01892 - this->_M_impl._M_start._M_first; 01893 if (__n > __vacancies) 01894 _M_new_elements_at_front(__n - __vacancies); 01895 return this->_M_impl._M_start - difference_type(__n); 01896 } 01897 01898 iterator 01899 _M_reserve_elements_at_back(size_type __n) 01900 { 01901 const size_type __vacancies = (this->_M_impl._M_finish._M_last 01902 - this->_M_impl._M_finish._M_cur) - 1; 01903 if (__n > __vacancies) 01904 _M_new_elements_at_back(__n - __vacancies); 01905 return this->_M_impl._M_finish + difference_type(__n); 01906 } 01907 01908 void 01909 _M_new_elements_at_front(size_type __new_elements); 01910 01911 void 01912 _M_new_elements_at_back(size_type __new_elements); 01913 //@} 01914 01915 01916 //@{ 01917 /** 01918 * @brief Memory-handling helpers for the major %map. 01919 * 01920 * Makes sure the _M_map has space for new nodes. Does not 01921 * actually add the nodes. Can invalidate _M_map pointers. 01922 * (And consequently, %deque iterators.) 01923 */ 01924 void 01925 _M_reserve_map_at_back(size_type __nodes_to_add = 1) 01926 { 01927 if (__nodes_to_add + 1 > this->_M_impl._M_map_size 01928 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map)) 01929 _M_reallocate_map(__nodes_to_add, false); 01930 } 01931 01932 void 01933 _M_reserve_map_at_front(size_type __nodes_to_add = 1) 01934 { 01935 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node 01936 - this->_M_impl._M_map)) 01937 _M_reallocate_map(__nodes_to_add, true); 01938 } 01939 01940 void 01941 _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front); 01942 //@} 01943 }; 01944 01945 01946 /** 01947 * @brief Deque equality comparison. 01948 * @param __x A %deque. 01949 * @param __y A %deque of the same type as @a __x. 01950 * @return True iff the size and elements of the deques are equal. 01951 * 01952 * This is an equivalence relation. It is linear in the size of the 01953 * deques. Deques are considered equivalent if their sizes are equal, 01954 * and if corresponding elements compare equal. 01955 */ 01956 template<typename _Tp, typename _Alloc> 01957 inline bool 01958 operator==(const deque<_Tp, _Alloc>& __x, 01959 const deque<_Tp, _Alloc>& __y) 01960 { return __x.size() == __y.size() 01961 && std::equal(__x.begin(), __x.end(), __y.begin()); } 01962 01963 /** 01964 * @brief Deque ordering relation. 01965 * @param __x A %deque. 01966 * @param __y A %deque of the same type as @a __x. 01967 * @return True iff @a x is lexicographically less than @a __y. 01968 * 01969 * This is a total ordering relation. It is linear in the size of the 01970 * deques. The elements must be comparable with @c <. 01971 * 01972 * See std::lexicographical_compare() for how the determination is made. 01973 */ 01974 template<typename _Tp, typename _Alloc> 01975 inline bool 01976 operator<(const deque<_Tp, _Alloc>& __x, 01977 const deque<_Tp, _Alloc>& __y) 01978 { return std::lexicographical_compare(__x.begin(), __x.end(), 01979 __y.begin(), __y.end()); } 01980 01981 /// Based on operator== 01982 template<typename _Tp, typename _Alloc> 01983 inline bool 01984 operator!=(const deque<_Tp, _Alloc>& __x, 01985 const deque<_Tp, _Alloc>& __y) 01986 { return !(__x == __y); } 01987 01988 /// Based on operator< 01989 template<typename _Tp, typename _Alloc> 01990 inline bool 01991 operator>(const deque<_Tp, _Alloc>& __x, 01992 const deque<_Tp, _Alloc>& __y) 01993 { return __y < __x; } 01994 01995 /// Based on operator< 01996 template<typename _Tp, typename _Alloc> 01997 inline bool 01998 operator<=(const deque<_Tp, _Alloc>& __x, 01999 const deque<_Tp, _Alloc>& __y) 02000 { return !(__y < __x); } 02001 02002 /// Based on operator< 02003 template<typename _Tp, typename _Alloc> 02004 inline bool 02005 operator>=(const deque<_Tp, _Alloc>& __x, 02006 const deque<_Tp, _Alloc>& __y) 02007 { return !(__x < __y); } 02008 02009 /// See std::deque::swap(). 02010 template<typename _Tp, typename _Alloc> 02011 inline void 02012 swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y) 02013 { __x.swap(__y); } 02014 02015 #undef _GLIBCXX_DEQUE_BUF_SIZE 02016 02017 _GLIBCXX_END_NAMESPACE_CONTAINER 02018 } // namespace std 02019 02020 #endif /* _STL_DEQUE_H */