00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
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 #include <initializer_list>
00064
00065 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 #ifndef _GLIBCXX_DEQUE_BUF_SIZE
00081 #define _GLIBCXX_DEQUE_BUF_SIZE 512
00082 #endif
00083
00084 inline size_t
00085 __deque_buf_size(size_t __size)
00086 { return (__size < _GLIBCXX_DEQUE_BUF_SIZE
00087 ? size_t(_GLIBCXX_DEQUE_BUF_SIZE / __size) : size_t(1)); }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 template<typename _Tp, typename _Ref, typename _Ptr>
00102 struct _Deque_iterator
00103 {
00104 typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator;
00105 typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
00106
00107 static size_t _S_buffer_size()
00108 { return __deque_buf_size(sizeof(_Tp)); }
00109
00110 typedef std::random_access_iterator_tag iterator_category;
00111 typedef _Tp value_type;
00112 typedef _Ptr pointer;
00113 typedef _Ref reference;
00114 typedef size_t size_type;
00115 typedef ptrdiff_t difference_type;
00116 typedef _Tp** _Map_pointer;
00117 typedef _Deque_iterator _Self;
00118
00119 _Tp* _M_cur;
00120 _Tp* _M_first;
00121 _Tp* _M_last;
00122 _Map_pointer _M_node;
00123
00124 _Deque_iterator(_Tp* __x, _Map_pointer __y)
00125 : _M_cur(__x), _M_first(*__y),
00126 _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
00127
00128 _Deque_iterator()
00129 : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) { }
00130
00131 _Deque_iterator(const iterator& __x)
00132 : _M_cur(__x._M_cur), _M_first(__x._M_first),
00133 _M_last(__x._M_last), _M_node(__x._M_node) { }
00134
00135 reference
00136 operator*() const
00137 { return *_M_cur; }
00138
00139 pointer
00140 operator->() const
00141 { return _M_cur; }
00142
00143 _Self&
00144 operator++()
00145 {
00146 ++_M_cur;
00147 if (_M_cur == _M_last)
00148 {
00149 _M_set_node(_M_node + 1);
00150 _M_cur = _M_first;
00151 }
00152 return *this;
00153 }
00154
00155 _Self
00156 operator++(int)
00157 {
00158 _Self __tmp = *this;
00159 ++*this;
00160 return __tmp;
00161 }
00162
00163 _Self&
00164 operator--()
00165 {
00166 if (_M_cur == _M_first)
00167 {
00168 _M_set_node(_M_node - 1);
00169 _M_cur = _M_last;
00170 }
00171 --_M_cur;
00172 return *this;
00173 }
00174
00175 _Self
00176 operator--(int)
00177 {
00178 _Self __tmp = *this;
00179 --*this;
00180 return __tmp;
00181 }
00182
00183 _Self&
00184 operator+=(difference_type __n)
00185 {
00186 const difference_type __offset = __n + (_M_cur - _M_first);
00187 if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
00188 _M_cur += __n;
00189 else
00190 {
00191 const difference_type __node_offset =
00192 __offset > 0 ? __offset / difference_type(_S_buffer_size())
00193 : -difference_type((-__offset - 1)
00194 / _S_buffer_size()) - 1;
00195 _M_set_node(_M_node + __node_offset);
00196 _M_cur = _M_first + (__offset - __node_offset
00197 * difference_type(_S_buffer_size()));
00198 }
00199 return *this;
00200 }
00201
00202 _Self
00203 operator+(difference_type __n) const
00204 {
00205 _Self __tmp = *this;
00206 return __tmp += __n;
00207 }
00208
00209 _Self&
00210 operator-=(difference_type __n)
00211 { return *this += -__n; }
00212
00213 _Self
00214 operator-(difference_type __n) const
00215 {
00216 _Self __tmp = *this;
00217 return __tmp -= __n;
00218 }
00219
00220 reference
00221 operator[](difference_type __n) const
00222 { return *(*this + __n); }
00223
00224
00225
00226
00227
00228
00229 void
00230 _M_set_node(_Map_pointer __new_node)
00231 {
00232 _M_node = __new_node;
00233 _M_first = *__new_node;
00234 _M_last = _M_first + difference_type(_S_buffer_size());
00235 }
00236 };
00237
00238
00239
00240
00241 template<typename _Tp, typename _Ref, typename _Ptr>
00242 inline bool
00243 operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00244 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00245 { return __x._M_cur == __y._M_cur; }
00246
00247 template<typename _Tp, typename _RefL, typename _PtrL,
00248 typename _RefR, typename _PtrR>
00249 inline bool
00250 operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00251 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00252 { return __x._M_cur == __y._M_cur; }
00253
00254 template<typename _Tp, typename _Ref, typename _Ptr>
00255 inline bool
00256 operator!=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00257 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00258 { return !(__x == __y); }
00259
00260 template<typename _Tp, typename _RefL, typename _PtrL,
00261 typename _RefR, typename _PtrR>
00262 inline bool
00263 operator!=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00264 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00265 { return !(__x == __y); }
00266
00267 template<typename _Tp, typename _Ref, typename _Ptr>
00268 inline bool
00269 operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00270 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00271 { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
00272 : (__x._M_node < __y._M_node); }
00273
00274 template<typename _Tp, typename _RefL, typename _PtrL,
00275 typename _RefR, typename _PtrR>
00276 inline bool
00277 operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00278 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00279 { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
00280 : (__x._M_node < __y._M_node); }
00281
00282 template<typename _Tp, typename _Ref, typename _Ptr>
00283 inline bool
00284 operator>(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00285 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00286 { return __y < __x; }
00287
00288 template<typename _Tp, typename _RefL, typename _PtrL,
00289 typename _RefR, typename _PtrR>
00290 inline bool
00291 operator>(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00292 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00293 { return __y < __x; }
00294
00295 template<typename _Tp, typename _Ref, typename _Ptr>
00296 inline bool
00297 operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00298 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00299 { return !(__y < __x); }
00300
00301 template<typename _Tp, typename _RefL, typename _PtrL,
00302 typename _RefR, typename _PtrR>
00303 inline bool
00304 operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00305 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00306 { return !(__y < __x); }
00307
00308 template<typename _Tp, typename _Ref, typename _Ptr>
00309 inline bool
00310 operator>=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00311 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00312 { return !(__x < __y); }
00313
00314 template<typename _Tp, typename _RefL, typename _PtrL,
00315 typename _RefR, typename _PtrR>
00316 inline bool
00317 operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00318 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00319 { return !(__x < __y); }
00320
00321
00322
00323
00324
00325 template<typename _Tp, typename _Ref, typename _Ptr>
00326 inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
00327 operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00328 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00329 {
00330 return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
00331 (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size())
00332 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
00333 + (__y._M_last - __y._M_cur);
00334 }
00335
00336 template<typename _Tp, typename _RefL, typename _PtrL,
00337 typename _RefR, typename _PtrR>
00338 inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
00339 operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00340 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00341 {
00342 return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
00343 (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size())
00344 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
00345 + (__y._M_last - __y._M_cur);
00346 }
00347
00348 template<typename _Tp, typename _Ref, typename _Ptr>
00349 inline _Deque_iterator<_Tp, _Ref, _Ptr>
00350 operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
00351 { return __x + __n; }
00352
00353 template<typename _Tp>
00354 void
00355 fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>& __first,
00356 const _Deque_iterator<_Tp, _Tp&, _Tp*>& __last, const _Tp& __value);
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 template<typename _Tp, typename _Alloc>
00369 class _Deque_base
00370 {
00371 public:
00372 typedef _Alloc allocator_type;
00373
00374 allocator_type
00375 get_allocator() const
00376 { return allocator_type(_M_get_Tp_allocator()); }
00377
00378 typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator;
00379 typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
00380
00381 _Deque_base()
00382 : _M_impl()
00383 { _M_initialize_map(0); }
00384
00385 _Deque_base(const allocator_type& __a, size_t __num_elements)
00386 : _M_impl(__a)
00387 { _M_initialize_map(__num_elements); }
00388
00389 _Deque_base(const allocator_type& __a)
00390 : _M_impl(__a)
00391 { }
00392
00393 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00394 _Deque_base(_Deque_base&& __x)
00395 : _M_impl(__x._M_get_Tp_allocator())
00396 {
00397 _M_initialize_map(0);
00398 if (__x._M_impl._M_map)
00399 {
00400 std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
00401 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
00402 std::swap(this->_M_impl._M_map, __x._M_impl._M_map);
00403 std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size);
00404 }
00405 }
00406 #endif
00407
00408 ~_Deque_base();
00409
00410 protected:
00411
00412
00413
00414 typedef typename _Alloc::template rebind<_Tp*>::other _Map_alloc_type;
00415
00416 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
00417
00418 struct _Deque_impl
00419 : public _Tp_alloc_type
00420 {
00421 _Tp** _M_map;
00422 size_t _M_map_size;
00423 iterator _M_start;
00424 iterator _M_finish;
00425
00426 _Deque_impl()
00427 : _Tp_alloc_type(), _M_map(0), _M_map_size(0),
00428 _M_start(), _M_finish()
00429 { }
00430
00431 _Deque_impl(const _Tp_alloc_type& __a)
00432 : _Tp_alloc_type(__a), _M_map(0), _M_map_size(0),
00433 _M_start(), _M_finish()
00434 { }
00435 };
00436
00437 _Tp_alloc_type&
00438 _M_get_Tp_allocator()
00439 { return *static_cast<_Tp_alloc_type*>(&this->_M_impl); }
00440
00441 const _Tp_alloc_type&
00442 _M_get_Tp_allocator() const
00443 { return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); }
00444
00445 _Map_alloc_type
00446 _M_get_map_allocator() const
00447 { return _Map_alloc_type(_M_get_Tp_allocator()); }
00448
00449 _Tp*
00450 _M_allocate_node()
00451 {
00452 return _M_impl._Tp_alloc_type::allocate(__deque_buf_size(sizeof(_Tp)));
00453 }
00454
00455 void
00456 _M_deallocate_node(_Tp* __p)
00457 {
00458 _M_impl._Tp_alloc_type::deallocate(__p, __deque_buf_size(sizeof(_Tp)));
00459 }
00460
00461 _Tp**
00462 _M_allocate_map(size_t __n)
00463 { return _M_get_map_allocator().allocate(__n); }
00464
00465 void
00466 _M_deallocate_map(_Tp** __p, size_t __n)
00467 { _M_get_map_allocator().deallocate(__p, __n); }
00468
00469 protected:
00470 void _M_initialize_map(size_t);
00471 void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
00472 void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
00473 enum { _S_initial_map_size = 8 };
00474
00475 _Deque_impl _M_impl;
00476 };
00477
00478 template<typename _Tp, typename _Alloc>
00479 _Deque_base<_Tp, _Alloc>::
00480 ~_Deque_base()
00481 {
00482 if (this->_M_impl._M_map)
00483 {
00484 _M_destroy_nodes(this->_M_impl._M_start._M_node,
00485 this->_M_impl._M_finish._M_node + 1);
00486 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
00487 }
00488 }
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498 template<typename _Tp, typename _Alloc>
00499 void
00500 _Deque_base<_Tp, _Alloc>::
00501 _M_initialize_map(size_t __num_elements)
00502 {
00503 const size_t __num_nodes = (__num_elements/ __deque_buf_size(sizeof(_Tp))
00504 + 1);
00505
00506 this->_M_impl._M_map_size = std::max((size_t) _S_initial_map_size,
00507 size_t(__num_nodes + 2));
00508 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
00509
00510
00511
00512
00513
00514
00515 _Tp** __nstart = (this->_M_impl._M_map
00516 + (this->_M_impl._M_map_size - __num_nodes) / 2);
00517 _Tp** __nfinish = __nstart + __num_nodes;
00518
00519 __try
00520 { _M_create_nodes(__nstart, __nfinish); }
00521 __catch(...)
00522 {
00523 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
00524 this->_M_impl._M_map = 0;
00525 this->_M_impl._M_map_size = 0;
00526 __throw_exception_again;
00527 }
00528
00529 this->_M_impl._M_start._M_set_node(__nstart);
00530 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
00531 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
00532 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
00533 + __num_elements
00534 % __deque_buf_size(sizeof(_Tp)));
00535 }
00536
00537 template<typename _Tp, typename _Alloc>
00538 void
00539 _Deque_base<_Tp, _Alloc>::
00540 _M_create_nodes(_Tp** __nstart, _Tp** __nfinish)
00541 {
00542 _Tp** __cur;
00543 __try
00544 {
00545 for (__cur = __nstart; __cur < __nfinish; ++__cur)
00546 *__cur = this->_M_allocate_node();
00547 }
00548 __catch(...)
00549 {
00550 _M_destroy_nodes(__nstart, __cur);
00551 __throw_exception_again;
00552 }
00553 }
00554
00555 template<typename _Tp, typename _Alloc>
00556 void
00557 _Deque_base<_Tp, _Alloc>::
00558 _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish)
00559 {
00560 for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
00561 _M_deallocate_node(*__n);
00562 }
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645 template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
00646 class deque : protected _Deque_base<_Tp, _Alloc>
00647 {
00648
00649 typedef typename _Alloc::value_type _Alloc_value_type;
00650 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
00651 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
00652
00653 typedef _Deque_base<_Tp, _Alloc> _Base;
00654 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
00655
00656 public:
00657 typedef _Tp value_type;
00658 typedef typename _Tp_alloc_type::pointer pointer;
00659 typedef typename _Tp_alloc_type::const_pointer const_pointer;
00660 typedef typename _Tp_alloc_type::reference reference;
00661 typedef typename _Tp_alloc_type::const_reference const_reference;
00662 typedef typename _Base::iterator iterator;
00663 typedef typename _Base::const_iterator const_iterator;
00664 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00665 typedef std::reverse_iterator<iterator> reverse_iterator;
00666 typedef size_t size_type;
00667 typedef ptrdiff_t difference_type;
00668 typedef _Alloc allocator_type;
00669
00670 protected:
00671 typedef pointer* _Map_pointer;
00672
00673 static size_t _S_buffer_size()
00674 { return __deque_buf_size(sizeof(_Tp)); }
00675
00676
00677 using _Base::_M_initialize_map;
00678 using _Base::_M_create_nodes;
00679 using _Base::_M_destroy_nodes;
00680 using _Base::_M_allocate_node;
00681 using _Base::_M_deallocate_node;
00682 using _Base::_M_allocate_map;
00683 using _Base::_M_deallocate_map;
00684 using _Base::_M_get_Tp_allocator;
00685
00686
00687
00688
00689
00690 using _Base::_M_impl;
00691
00692 public:
00693
00694
00695
00696
00697
00698 deque()
00699 : _Base() { }
00700
00701
00702
00703
00704
00705 explicit
00706 deque(const allocator_type& __a)
00707 : _Base(__a, 0) { }
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717 explicit
00718 deque(size_type __n, const value_type& __value = value_type(),
00719 const allocator_type& __a = allocator_type())
00720 : _Base(__a, __n)
00721 { _M_fill_initialize(__value); }
00722
00723
00724
00725
00726
00727
00728
00729
00730 deque(const deque& __x)
00731 : _Base(__x._M_get_Tp_allocator(), __x.size())
00732 { std::__uninitialized_copy_a(__x.begin(), __x.end(),
00733 this->_M_impl._M_start,
00734 _M_get_Tp_allocator()); }
00735
00736 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00737
00738
00739
00740
00741
00742
00743
00744 deque(deque&& __x)
00745 : _Base(std::forward<_Base>(__x)) { }
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758 deque(initializer_list<value_type> __l,
00759 const allocator_type& __a = allocator_type())
00760 : _Base(__a)
00761 {
00762 _M_range_initialize(__l.begin(), __l.end(),
00763 random_access_iterator_tag());
00764 }
00765 #endif
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782 template<typename _InputIterator>
00783 deque(_InputIterator __first, _InputIterator __last,
00784 const allocator_type& __a = allocator_type())
00785 : _Base(__a)
00786 {
00787
00788 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
00789 _M_initialize_dispatch(__first, __last, _Integral());
00790 }
00791
00792
00793
00794
00795
00796
00797 ~deque()
00798 { _M_destroy_data(begin(), end(), _M_get_Tp_allocator()); }
00799
00800
00801
00802
00803
00804
00805
00806
00807 deque&
00808 operator=(const deque& __x);
00809
00810 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00811
00812
00813
00814
00815
00816
00817
00818 deque&
00819 operator=(deque&& __x)
00820 {
00821
00822 this->clear();
00823 this->swap(__x);
00824 return *this;
00825 }
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838 deque&
00839 operator=(initializer_list<value_type> __l)
00840 {
00841 this->assign(__l.begin(), __l.end());
00842 return *this;
00843 }
00844 #endif
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856 void
00857 assign(size_type __n, const value_type& __val)
00858 { _M_fill_assign(__n, __val); }
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872 template<typename _InputIterator>
00873 void
00874 assign(_InputIterator __first, _InputIterator __last)
00875 {
00876 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
00877 _M_assign_dispatch(__first, __last, _Integral());
00878 }
00879
00880 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892 void
00893 assign(initializer_list<value_type> __l)
00894 { this->assign(__l.begin(), __l.end()); }
00895 #endif
00896
00897
00898 allocator_type
00899 get_allocator() const
00900 { return _Base::get_allocator(); }
00901
00902
00903
00904
00905
00906
00907 iterator
00908 begin()
00909 { return this->_M_impl._M_start; }
00910
00911
00912
00913
00914
00915 const_iterator
00916 begin() const
00917 { return this->_M_impl._M_start; }
00918
00919
00920
00921
00922
00923
00924 iterator
00925 end()
00926 { return this->_M_impl._M_finish; }
00927
00928
00929
00930
00931
00932
00933 const_iterator
00934 end() const
00935 { return this->_M_impl._M_finish; }
00936
00937
00938
00939
00940
00941
00942 reverse_iterator
00943 rbegin()
00944 { return reverse_iterator(this->_M_impl._M_finish); }
00945
00946
00947
00948
00949
00950
00951 const_reverse_iterator
00952 rbegin() const
00953 { return const_reverse_iterator(this->_M_impl._M_finish); }
00954
00955
00956
00957
00958
00959
00960 reverse_iterator
00961 rend()
00962 { return reverse_iterator(this->_M_impl._M_start); }
00963
00964
00965
00966
00967
00968
00969 const_reverse_iterator
00970 rend() const
00971 { return const_reverse_iterator(this->_M_impl._M_start); }
00972
00973 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00974
00975
00976
00977
00978 const_iterator
00979 cbegin() const
00980 { return this->_M_impl._M_start; }
00981
00982
00983
00984
00985
00986
00987 const_iterator
00988 cend() const
00989 { return this->_M_impl._M_finish; }
00990
00991
00992
00993
00994
00995
00996 const_reverse_iterator
00997 crbegin() const
00998 { return const_reverse_iterator(this->_M_impl._M_finish); }
00999
01000
01001
01002
01003
01004
01005 const_reverse_iterator
01006 crend() const
01007 { return const_reverse_iterator(this->_M_impl._M_start); }
01008 #endif
01009
01010
01011
01012 size_type
01013 size() const
01014 { return this->_M_impl._M_finish - this->_M_impl._M_start; }
01015
01016
01017 size_type
01018 max_size() const
01019 { return _M_get_Tp_allocator().max_size(); }
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032 void
01033 resize(size_type __new_size, value_type __x = value_type())
01034 {
01035 const size_type __len = size();
01036 if (__new_size < __len)
01037 _M_erase_at_end(this->_M_impl._M_start + difference_type(__new_size));
01038 else
01039 insert(this->_M_impl._M_finish, __new_size - __len, __x);
01040 }
01041
01042
01043
01044
01045
01046 bool
01047 empty() const
01048 { return this->_M_impl._M_finish == this->_M_impl._M_start; }
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062 reference
01063 operator[](size_type __n)
01064 { return this->_M_impl._M_start[difference_type(__n)]; }
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077 const_reference
01078 operator[](size_type __n) const
01079 { return this->_M_impl._M_start[difference_type(__n)]; }
01080
01081 protected:
01082
01083 void
01084 _M_range_check(size_type __n) const
01085 {
01086 if (__n >= this->size())
01087 __throw_out_of_range(__N("deque::_M_range_check"));
01088 }
01089
01090 public:
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102 reference
01103 at(size_type __n)
01104 {
01105 _M_range_check(__n);
01106 return (*this)[__n];
01107 }
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120 const_reference
01121 at(size_type __n) const
01122 {
01123 _M_range_check(__n);
01124 return (*this)[__n];
01125 }
01126
01127
01128
01129
01130
01131 reference
01132 front()
01133 { return *begin(); }
01134
01135
01136
01137
01138
01139 const_reference
01140 front() const
01141 { return *begin(); }
01142
01143
01144
01145
01146
01147 reference
01148 back()
01149 {
01150 iterator __tmp = end();
01151 --__tmp;
01152 return *__tmp;
01153 }
01154
01155
01156
01157
01158
01159 const_reference
01160 back() const
01161 {
01162 const_iterator __tmp = end();
01163 --__tmp;
01164 return *__tmp;
01165 }
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177 void
01178 push_front(const value_type& __x)
01179 {
01180 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
01181 {
01182 this->_M_impl.construct(this->_M_impl._M_start._M_cur - 1, __x);
01183 --this->_M_impl._M_start._M_cur;
01184 }
01185 else
01186 _M_push_front_aux(__x);
01187 }
01188
01189 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01190 void
01191 push_front(value_type&& __x)
01192 { emplace_front(std::move(__x)); }
01193
01194 template<typename... _Args>
01195 void
01196 emplace_front(_Args&&... __args);
01197 #endif
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208 void
01209 push_back(const value_type& __x)
01210 {
01211 if (this->_M_impl._M_finish._M_cur
01212 != this->_M_impl._M_finish._M_last - 1)
01213 {
01214 this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __x);
01215 ++this->_M_impl._M_finish._M_cur;
01216 }
01217 else
01218 _M_push_back_aux(__x);
01219 }
01220
01221 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01222 void
01223 push_back(value_type&& __x)
01224 { emplace_back(std::move(__x)); }
01225
01226 template<typename... _Args>
01227 void
01228 emplace_back(_Args&&... __args);
01229 #endif
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239 void
01240 pop_front()
01241 {
01242 if (this->_M_impl._M_start._M_cur
01243 != this->_M_impl._M_start._M_last - 1)
01244 {
01245 this->_M_impl.destroy(this->_M_impl._M_start._M_cur);
01246 ++this->_M_impl._M_start._M_cur;
01247 }
01248 else
01249 _M_pop_front_aux();
01250 }
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260 void
01261 pop_back()
01262 {
01263 if (this->_M_impl._M_finish._M_cur
01264 != this->_M_impl._M_finish._M_first)
01265 {
01266 --this->_M_impl._M_finish._M_cur;
01267 this->_M_impl.destroy(this->_M_impl._M_finish._M_cur);
01268 }
01269 else
01270 _M_pop_back_aux();
01271 }
01272
01273 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283 template<typename... _Args>
01284 iterator
01285 emplace(iterator __position, _Args&&... __args);
01286 #endif
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297 iterator
01298 insert(iterator __position, const value_type& __x);
01299
01300 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310 iterator
01311 insert(iterator __position, value_type&& __x)
01312 { return emplace(__position, std::move(__x)); }
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323 void
01324 insert(iterator __p, initializer_list<value_type> __l)
01325 { this->insert(__p, __l.begin(), __l.end()); }
01326 #endif
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337 void
01338 insert(iterator __position, size_type __n, const value_type& __x)
01339 { _M_fill_insert(__position, __n, __x); }
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351 template<typename _InputIterator>
01352 void
01353 insert(iterator __position, _InputIterator __first,
01354 _InputIterator __last)
01355 {
01356
01357 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
01358 _M_insert_dispatch(__position, __first, __last, _Integral());
01359 }
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374 iterator
01375 erase(iterator __position);
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393 iterator
01394 erase(iterator __first, iterator __last);
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405 void
01406 swap(deque& __x)
01407 {
01408 std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
01409 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
01410 std::swap(this->_M_impl._M_map, __x._M_impl._M_map);
01411 std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size);
01412
01413
01414
01415 std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(),
01416 __x._M_get_Tp_allocator());
01417 }
01418
01419
01420
01421
01422
01423
01424
01425 void
01426 clear()
01427 { _M_erase_at_end(begin()); }
01428
01429 protected:
01430
01431
01432
01433
01434
01435
01436 template<typename _Integer>
01437 void
01438 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
01439 {
01440 _M_initialize_map(static_cast<size_type>(__n));
01441 _M_fill_initialize(__x);
01442 }
01443
01444
01445 template<typename _InputIterator>
01446 void
01447 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
01448 __false_type)
01449 {
01450 typedef typename std::iterator_traits<_InputIterator>::
01451 iterator_category _IterCategory;
01452 _M_range_initialize(__first, __last, _IterCategory());
01453 }
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467 template<typename _InputIterator>
01468 void
01469 _M_range_initialize(_InputIterator __first, _InputIterator __last,
01470 std::input_iterator_tag);
01471
01472
01473 template<typename _ForwardIterator>
01474 void
01475 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
01476 std::forward_iterator_tag);
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489 void
01490 _M_fill_initialize(const value_type& __value);
01491
01492
01493
01494
01495
01496
01497
01498
01499 template<typename _Integer>
01500 void
01501 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
01502 { _M_fill_assign(__n, __val); }
01503
01504
01505 template<typename _InputIterator>
01506 void
01507 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
01508 __false_type)
01509 {
01510 typedef typename std::iterator_traits<_InputIterator>::
01511 iterator_category _IterCategory;
01512 _M_assign_aux(__first, __last, _IterCategory());
01513 }
01514
01515
01516 template<typename _InputIterator>
01517 void
01518 _M_assign_aux(_InputIterator __first, _InputIterator __last,
01519 std::input_iterator_tag);
01520
01521
01522 template<typename _ForwardIterator>
01523 void
01524 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
01525 std::forward_iterator_tag)
01526 {
01527 const size_type __len = std::distance(__first, __last);
01528 if (__len > size())
01529 {
01530 _ForwardIterator __mid = __first;
01531 std::advance(__mid, size());
01532 std::copy(__first, __mid, begin());
01533 insert(end(), __mid, __last);
01534 }
01535 else
01536 _M_erase_at_end(std::copy(__first, __last, begin()));
01537 }
01538
01539
01540
01541 void
01542 _M_fill_assign(size_type __n, const value_type& __val)
01543 {
01544 if (__n > size())
01545 {
01546 std::fill(begin(), end(), __val);
01547 insert(end(), __n - size(), __val);
01548 }
01549 else
01550 {
01551 _M_erase_at_end(begin() + difference_type(__n));
01552 std::fill(begin(), end(), __val);
01553 }
01554 }
01555
01556
01557
01558 #ifndef __GXX_EXPERIMENTAL_CXX0X__
01559 void _M_push_back_aux(const value_type&);
01560
01561 void _M_push_front_aux(const value_type&);
01562 #else
01563 template<typename... _Args>
01564 void _M_push_back_aux(_Args&&... __args);
01565
01566 template<typename... _Args>
01567 void _M_push_front_aux(_Args&&... __args);
01568 #endif
01569
01570 void _M_pop_back_aux();
01571
01572 void _M_pop_front_aux();
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582 template<typename _Integer>
01583 void
01584 _M_insert_dispatch(iterator __pos,
01585 _Integer __n, _Integer __x, __true_type)
01586 { _M_fill_insert(__pos, __n, __x); }
01587
01588
01589 template<typename _InputIterator>
01590 void
01591 _M_insert_dispatch(iterator __pos,
01592 _InputIterator __first, _InputIterator __last,
01593 __false_type)
01594 {
01595 typedef typename std::iterator_traits<_InputIterator>::
01596 iterator_category _IterCategory;
01597 _M_range_insert_aux(__pos, __first, __last, _IterCategory());
01598 }
01599
01600
01601 template<typename _InputIterator>
01602 void
01603 _M_range_insert_aux(iterator __pos, _InputIterator __first,
01604 _InputIterator __last, std::input_iterator_tag);
01605
01606
01607 template<typename _ForwardIterator>
01608 void
01609 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
01610 _ForwardIterator __last, std::forward_iterator_tag);
01611
01612
01613
01614
01615 void
01616 _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
01617
01618
01619 #ifndef __GXX_EXPERIMENTAL_CXX0X__
01620 iterator
01621 _M_insert_aux(iterator __pos, const value_type& __x);
01622 #else
01623 template<typename... _Args>
01624 iterator
01625 _M_insert_aux(iterator __pos, _Args&&... __args);
01626 #endif
01627
01628
01629 void
01630 _M_insert_aux(iterator __pos, size_type __n, const value_type& __x);
01631
01632
01633 template<typename _ForwardIterator>
01634 void
01635 _M_insert_aux(iterator __pos,
01636 _ForwardIterator __first, _ForwardIterator __last,
01637 size_type __n);
01638
01639
01640
01641
01642 void
01643 _M_destroy_data_aux(iterator __first, iterator __last);
01644
01645
01646
01647 template<typename _Alloc1>
01648 void
01649 _M_destroy_data(iterator __first, iterator __last, const _Alloc1&)
01650 { _M_destroy_data_aux(__first, __last); }
01651
01652 void
01653 _M_destroy_data(iterator __first, iterator __last,
01654 const std::allocator<_Tp>&)
01655 {
01656 if (!__has_trivial_destructor(value_type))
01657 _M_destroy_data_aux(__first, __last);
01658 }
01659
01660
01661 void
01662 _M_erase_at_begin(iterator __pos)
01663 {
01664 _M_destroy_data(begin(), __pos, _M_get_Tp_allocator());
01665 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
01666 this->_M_impl._M_start = __pos;
01667 }
01668
01669
01670
01671 void
01672 _M_erase_at_end(iterator __pos)
01673 {
01674 _M_destroy_data(__pos, end(), _M_get_Tp_allocator());
01675 _M_destroy_nodes(__pos._M_node + 1,
01676 this->_M_impl._M_finish._M_node + 1);
01677 this->_M_impl._M_finish = __pos;
01678 }
01679
01680
01681
01682 iterator
01683 _M_reserve_elements_at_front(size_type __n)
01684 {
01685 const size_type __vacancies = this->_M_impl._M_start._M_cur
01686 - this->_M_impl._M_start._M_first;
01687 if (__n > __vacancies)
01688 _M_new_elements_at_front(__n - __vacancies);
01689 return this->_M_impl._M_start - difference_type(__n);
01690 }
01691
01692 iterator
01693 _M_reserve_elements_at_back(size_type __n)
01694 {
01695 const size_type __vacancies = (this->_M_impl._M_finish._M_last
01696 - this->_M_impl._M_finish._M_cur) - 1;
01697 if (__n > __vacancies)
01698 _M_new_elements_at_back(__n - __vacancies);
01699 return this->_M_impl._M_finish + difference_type(__n);
01700 }
01701
01702 void
01703 _M_new_elements_at_front(size_type __new_elements);
01704
01705 void
01706 _M_new_elements_at_back(size_type __new_elements);
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718 void
01719 _M_reserve_map_at_back(size_type __nodes_to_add = 1)
01720 {
01721 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
01722 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
01723 _M_reallocate_map(__nodes_to_add, false);
01724 }
01725
01726 void
01727 _M_reserve_map_at_front(size_type __nodes_to_add = 1)
01728 {
01729 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
01730 - this->_M_impl._M_map))
01731 _M_reallocate_map(__nodes_to_add, true);
01732 }
01733
01734 void
01735 _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
01736
01737 };
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750 template<typename _Tp, typename _Alloc>
01751 inline bool
01752 operator==(const deque<_Tp, _Alloc>& __x,
01753 const deque<_Tp, _Alloc>& __y)
01754 { return __x.size() == __y.size()
01755 && std::equal(__x.begin(), __x.end(), __y.begin()); }
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768 template<typename _Tp, typename _Alloc>
01769 inline bool
01770 operator<(const deque<_Tp, _Alloc>& __x,
01771 const deque<_Tp, _Alloc>& __y)
01772 { return std::lexicographical_compare(__x.begin(), __x.end(),
01773 __y.begin(), __y.end()); }
01774
01775
01776 template<typename _Tp, typename _Alloc>
01777 inline bool
01778 operator!=(const deque<_Tp, _Alloc>& __x,
01779 const deque<_Tp, _Alloc>& __y)
01780 { return !(__x == __y); }
01781
01782
01783 template<typename _Tp, typename _Alloc>
01784 inline bool
01785 operator>(const deque<_Tp, _Alloc>& __x,
01786 const deque<_Tp, _Alloc>& __y)
01787 { return __y < __x; }
01788
01789
01790 template<typename _Tp, typename _Alloc>
01791 inline bool
01792 operator<=(const deque<_Tp, _Alloc>& __x,
01793 const deque<_Tp, _Alloc>& __y)
01794 { return !(__y < __x); }
01795
01796
01797 template<typename _Tp, typename _Alloc>
01798 inline bool
01799 operator>=(const deque<_Tp, _Alloc>& __x,
01800 const deque<_Tp, _Alloc>& __y)
01801 { return !(__x < __y); }
01802
01803
01804 template<typename _Tp, typename _Alloc>
01805 inline void
01806 swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
01807 { __x.swap(__y); }
01808
01809 #undef _GLIBCXX_DEQUE_BUF_SIZE
01810
01811 _GLIBCXX_END_NESTED_NAMESPACE
01812
01813 #endif