_deque.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. /*
  2. *
  3. * Copyright (c) 1994
  4. * Hewlett-Packard Company
  5. *
  6. * Copyright (c) 1996,1997
  7. * Silicon Graphics Computer Systems, Inc.
  8. *
  9. * Copyright (c) 1997
  10. * Moscow Center for SPARC Technology
  11. *
  12. * Copyright (c) 1999
  13. * Boris Fomitchev
  14. *
  15. * This material is provided "as is", with absolutely no warranty expressed
  16. * or implied. Any use is at your own risk.
  17. *
  18. * Permission to use or copy this software for any purpose is hereby granted
  19. * without fee, provided the above notices are retained on all copies.
  20. * Permission to modify the code and to distribute modified code is granted,
  21. * provided the above notices are retained, and a notice that the code was
  22. * modified is included with the above copyright notice.
  23. *
  24. */
  25. /* NOTE: This is an internal header file, included by other STL headers.
  26. * You should not attempt to use it directly.
  27. */
  28. #ifndef _STLP_INTERNAL_DEQUE_H
  29. #define _STLP_INTERNAL_DEQUE_H
  30. #ifndef _STLP_INTERNAL_ALGOBASE_H
  31. # include <stl/_algobase.h>
  32. #endif
  33. #ifndef _STLP_INTERNAL_ALLOC_H
  34. # include <stl/_alloc.h>
  35. #endif
  36. #ifndef _STLP_INTERNAL_ITERATOR_H
  37. # include <stl/_iterator.h>
  38. #endif
  39. #ifndef _STLP_INTERNAL_UNINITIALIZED_H
  40. # include <stl/_uninitialized.h>
  41. #endif
  42. #ifndef _STLP_RANGE_ERRORS_H
  43. # include <stl/_range_errors.h>
  44. #endif
  45. /* Class invariants:
  46. * For any nonsingular iterator i:
  47. * i.node is the address of an element in the map array. The
  48. * contents of i.node is a pointer to the beginning of a node.
  49. * i.first == *(i.node)
  50. * i.last == i.first + node_size
  51. * i.cur is a pointer in the range [i.first, i.last). NOTE:
  52. * the implication of this is that i.cur is always a dereferenceable
  53. * pointer, even if i is a past-the-end iterator.
  54. * Start and Finish are always nonsingular iterators. NOTE: this means
  55. * that an empty deque must have one node, and that a deque
  56. * with N elements, where N is the buffer size, must have two nodes.
  57. * For every node other than start.node and finish.node, every element
  58. * in the node is an initialized object. If start.node == finish.node,
  59. * then [start.cur, finish.cur) are initialized objects, and
  60. * the elements outside that range are uninitialized storage. Otherwise,
  61. * [start.cur, start.last) and [finish.first, finish.cur) are initialized
  62. * objects, and [start.first, start.cur) and [finish.cur, finish.last)
  63. * are uninitialized storage.
  64. * [map, map + map_size) is a valid, non-empty range.
  65. * [start.node, finish.node] is a valid range contained within
  66. * [map, map + map_size).
  67. * A pointer in the range [map, map + map_size) points to an allocated node
  68. * if and only if the pointer is in the range [start.node, finish.node].
  69. */
  70. _STLP_BEGIN_NAMESPACE
  71. _STLP_MOVE_TO_PRIV_NAMESPACE
  72. template <class _Tp>
  73. struct _Deque_iterator_base {
  74. static size_t _S_buffer_size() {
  75. const size_t blocksize = _MAX_BYTES;
  76. return (sizeof(_Tp) < blocksize ? (blocksize / sizeof(_Tp)) : 1);
  77. }
  78. typedef random_access_iterator_tag iterator_category;
  79. typedef _Tp value_type;
  80. typedef size_t size_type;
  81. typedef ptrdiff_t difference_type;
  82. typedef value_type** _Map_pointer;
  83. typedef _Deque_iterator_base< _Tp > _Self;
  84. value_type* _M_cur;
  85. value_type* _M_first;
  86. value_type* _M_last;
  87. _Map_pointer _M_node;
  88. _Deque_iterator_base(value_type* __x, _Map_pointer __y)
  89. : _M_cur(__x), _M_first(*__y),
  90. _M_last(*__y + _S_buffer_size()), _M_node(__y) {}
  91. _Deque_iterator_base() : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) {}
  92. // see comment in doc/README.evc4 and doc/README.evc8
  93. #if defined (_STLP_MSVC) && (_STLP_MSVC <= 1401) && defined (MIPS) && defined (NDEBUG)
  94. _Deque_iterator_base(_Deque_iterator_base const& __other)
  95. : _M_cur(__other._M_cur), _M_first(__other._M_first),
  96. _M_last(__other._M_last), _M_node(__other._M_node) {}
  97. #endif
  98. difference_type _M_subtract(const _Self& __x) const {
  99. return difference_type(_S_buffer_size()) * (_M_node - __x._M_node - 1) +
  100. (_M_cur - _M_first) + (__x._M_last - __x._M_cur);
  101. }
  102. void _M_increment() {
  103. if (++_M_cur == _M_last) {
  104. _M_set_node(_M_node + 1);
  105. _M_cur = _M_first;
  106. }
  107. }
  108. void _M_decrement() {
  109. if (_M_cur == _M_first) {
  110. _M_set_node(_M_node - 1);
  111. _M_cur = _M_last;
  112. }
  113. --_M_cur;
  114. }
  115. void _M_advance(difference_type __n) {
  116. const size_t buffersize = _S_buffer_size();
  117. difference_type __offset = __n + (_M_cur - _M_first);
  118. if (__offset >= 0 && __offset < difference_type(buffersize))
  119. _M_cur += __n;
  120. else {
  121. difference_type __node_offset =
  122. __offset > 0 ? __offset / buffersize
  123. : -difference_type((-__offset - 1) / buffersize) - 1;
  124. _M_set_node(_M_node + __node_offset);
  125. _M_cur = _M_first +
  126. (__offset - __node_offset * difference_type(buffersize));
  127. }
  128. }
  129. void _M_set_node(_Map_pointer __new_node) {
  130. _M_last = (_M_first = *(_M_node = __new_node)) + difference_type(_S_buffer_size());
  131. }
  132. };
  133. template <class _Tp, class _Traits>
  134. struct _Deque_iterator : public _Deque_iterator_base< _Tp> {
  135. typedef random_access_iterator_tag iterator_category;
  136. typedef _Tp value_type;
  137. typedef typename _Traits::reference reference;
  138. typedef typename _Traits::pointer pointer;
  139. typedef size_t size_type;
  140. typedef ptrdiff_t difference_type;
  141. typedef value_type** _Map_pointer;
  142. typedef _Deque_iterator_base< _Tp > _Base;
  143. typedef _Deque_iterator<_Tp, _Traits> _Self;
  144. typedef typename _Traits::_NonConstTraits _NonConstTraits;
  145. typedef _Deque_iterator<_Tp, _NonConstTraits> iterator;
  146. typedef typename _Traits::_ConstTraits _ConstTraits;
  147. typedef _Deque_iterator<_Tp, _ConstTraits> const_iterator;
  148. _Deque_iterator(value_type* __x, _Map_pointer __y) :
  149. _Deque_iterator_base<value_type>(__x,__y) {}
  150. _Deque_iterator() {}
  151. //copy constructor for iterator and constructor from iterator for const_iterator
  152. _Deque_iterator(const iterator& __x) :
  153. _Deque_iterator_base<value_type>(__x) {}
  154. reference operator*() const {
  155. return *this->_M_cur;
  156. }
  157. _STLP_DEFINE_ARROW_OPERATOR
  158. difference_type operator-(const const_iterator& __x) const { return this->_M_subtract(__x); }
  159. _Self& operator++() { this->_M_increment(); return *this; }
  160. _Self operator++(int) {
  161. _Self __tmp = *this;
  162. ++*this;
  163. return __tmp;
  164. }
  165. _Self& operator--() { this->_M_decrement(); return *this; }
  166. _Self operator--(int) {
  167. _Self __tmp = *this;
  168. --*this;
  169. return __tmp;
  170. }
  171. _Self& operator+=(difference_type __n) { this->_M_advance(__n); return *this; }
  172. _Self operator+(difference_type __n) const {
  173. _Self __tmp = *this;
  174. return __tmp += __n;
  175. }
  176. _Self& operator-=(difference_type __n) { return *this += -__n; }
  177. _Self operator-(difference_type __n) const {
  178. _Self __tmp = *this;
  179. return __tmp -= __n;
  180. }
  181. reference operator[](difference_type __n) const { return *(*this + __n); }
  182. };
  183. template <class _Tp, class _Traits>
  184. inline _Deque_iterator<_Tp, _Traits> _STLP_CALL
  185. operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Traits>& __x)
  186. { return __x + __n; }
  187. #if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
  188. template <class _Tp>
  189. inline bool _STLP_CALL
  190. operator==(const _Deque_iterator_base<_Tp >& __x,
  191. const _Deque_iterator_base<_Tp >& __y)
  192. { return __x._M_cur == __y._M_cur; }
  193. template <class _Tp>
  194. inline bool _STLP_CALL
  195. operator < (const _Deque_iterator_base<_Tp >& __x,
  196. const _Deque_iterator_base<_Tp >& __y) {
  197. return (__x._M_node == __y._M_node) ?
  198. (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node);
  199. }
  200. template <class _Tp>
  201. inline bool _STLP_CALL
  202. operator!=(const _Deque_iterator_base<_Tp >& __x,
  203. const _Deque_iterator_base<_Tp >& __y)
  204. { return __x._M_cur != __y._M_cur; }
  205. template <class _Tp>
  206. inline bool _STLP_CALL
  207. operator>(const _Deque_iterator_base<_Tp >& __x,
  208. const _Deque_iterator_base<_Tp >& __y)
  209. { return __y < __x; }
  210. template <class _Tp>
  211. inline bool _STLP_CALL operator>=(const _Deque_iterator_base<_Tp >& __x,
  212. const _Deque_iterator_base<_Tp >& __y)
  213. { return !(__x < __y); }
  214. template <class _Tp>
  215. inline bool _STLP_CALL operator<=(const _Deque_iterator_base<_Tp >& __x,
  216. const _Deque_iterator_base<_Tp >& __y)
  217. { return !(__y < __x); }
  218. #else /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
  219. template <class _Tp, class _Traits1, class _Traits2>
  220. inline bool _STLP_CALL
  221. operator==(const _Deque_iterator<_Tp, _Traits1 >& __x,
  222. const _Deque_iterator<_Tp, _Traits2 >& __y)
  223. { return __x._M_cur == __y._M_cur; }
  224. template <class _Tp, class _Traits1, class _Traits2>
  225. inline bool _STLP_CALL
  226. operator < (const _Deque_iterator<_Tp, _Traits1 >& __x,
  227. const _Deque_iterator<_Tp, _Traits2 >& __y) {
  228. return (__x._M_node == __y._M_node) ?
  229. (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node);
  230. }
  231. template <class _Tp>
  232. inline bool _STLP_CALL
  233. operator!=(const _Deque_iterator<_Tp, _Nonconst_traits<_Tp> >& __x,
  234. const _Deque_iterator<_Tp, _Const_traits<_Tp> >& __y)
  235. { return __x._M_cur != __y._M_cur; }
  236. template <class _Tp>
  237. inline bool _STLP_CALL
  238. operator>(const _Deque_iterator<_Tp, _Nonconst_traits<_Tp> >& __x,
  239. const _Deque_iterator<_Tp, _Const_traits<_Tp> >& __y)
  240. { return __y < __x; }
  241. template <class _Tp>
  242. inline bool _STLP_CALL
  243. operator>=(const _Deque_iterator<_Tp, _Nonconst_traits<_Tp> >& __x,
  244. const _Deque_iterator<_Tp, _Const_traits<_Tp> >& __y)
  245. { return !(__x < __y); }
  246. template <class _Tp>
  247. inline bool _STLP_CALL
  248. operator<=(const _Deque_iterator<_Tp, _Nonconst_traits<_Tp> >& __x,
  249. const _Deque_iterator<_Tp, _Const_traits<_Tp> >& __y)
  250. { return !(__y < __x); }
  251. #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
  252. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  253. _STLP_MOVE_TO_STD_NAMESPACE
  254. template <class _Tp, class _Traits>
  255. struct __type_traits<_STLP_PRIV _Deque_iterator<_Tp, _Traits> > {
  256. typedef __false_type has_trivial_default_constructor;
  257. typedef __true_type has_trivial_copy_constructor;
  258. typedef __true_type has_trivial_assignment_operator;
  259. typedef __true_type has_trivial_destructor;
  260. typedef __false_type is_POD_type;
  261. };
  262. _STLP_MOVE_TO_PRIV_NAMESPACE
  263. #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
  264. #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
  265. _STLP_MOVE_TO_STD_NAMESPACE
  266. template <class _Tp, class _Traits> inline _Tp* _STLP_CALL
  267. value_type(const _STLP_PRIV _Deque_iterator<_Tp, _Traits >&) { return (_Tp*)0; }
  268. template <class _Tp, class _Traits> inline random_access_iterator_tag _STLP_CALL
  269. iterator_category(const _STLP_PRIV _Deque_iterator<_Tp, _Traits >&) { return random_access_iterator_tag(); }
  270. template <class _Tp, class _Traits> inline ptrdiff_t* _STLP_CALL
  271. distance_type(const _STLP_PRIV _Deque_iterator<_Tp, _Traits >&) { return 0; }
  272. _STLP_MOVE_TO_PRIV_NAMESPACE
  273. #endif
  274. /* Deque base class. It has two purposes. First, its constructor
  275. * and destructor allocate (but don't initialize) storage. This makes
  276. * exception safety easier. Second, the base class encapsulates all of
  277. * the differences between SGI-style allocators and standard-conforming
  278. * allocators.
  279. */
  280. template <class _Tp, class _Alloc>
  281. class _Deque_base {
  282. typedef _Deque_base<_Tp, _Alloc> _Self;
  283. public:
  284. typedef _Tp value_type;
  285. _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
  286. typedef _Alloc allocator_type;
  287. typedef _STLP_alloc_proxy<size_t, value_type, allocator_type> _Alloc_proxy;
  288. typedef typename _Alloc_traits<_Tp*, _Alloc>::allocator_type _Map_alloc_type;
  289. typedef _STLP_alloc_proxy<value_type**, value_type*, _Map_alloc_type> _Map_alloc_proxy;
  290. typedef _Deque_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
  291. typedef _Deque_iterator<_Tp, _Const_traits<_Tp> > const_iterator;
  292. static size_t _STLP_CALL buffer_size() { return _Deque_iterator_base<_Tp>::_S_buffer_size(); }
  293. _Deque_base(const allocator_type& __a, size_t __num_elements)
  294. : _M_start(), _M_finish(), _M_map(_STLP_CONVERT_ALLOCATOR(__a, _Tp*), 0),
  295. _M_map_size(__a, (size_t)0)
  296. { _M_initialize_map(__num_elements); }
  297. _Deque_base(const allocator_type& __a)
  298. : _M_start(), _M_finish(), _M_map(_STLP_CONVERT_ALLOCATOR(__a, _Tp*), 0),
  299. _M_map_size(__a, (size_t)0) {}
  300. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  301. _Deque_base(__move_source<_Self> src)
  302. : _M_start(src.get()._M_start), _M_finish(src.get()._M_finish),
  303. _M_map(__move_source<_Map_alloc_proxy>(src.get()._M_map)),
  304. _M_map_size(__move_source<_Alloc_proxy>(src.get()._M_map_size)) {
  305. src.get()._M_map._M_data = 0;
  306. src.get()._M_map_size._M_data = 0;
  307. src.get()._M_finish = src.get()._M_start;
  308. }
  309. #endif
  310. ~_Deque_base();
  311. protected:
  312. void _M_initialize_map(size_t);
  313. void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
  314. void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
  315. enum { _S_initial_map_size = 8 };
  316. protected:
  317. iterator _M_start;
  318. iterator _M_finish;
  319. _Map_alloc_proxy _M_map;
  320. _Alloc_proxy _M_map_size;
  321. };
  322. #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
  323. # define deque _STLP_PTR_IMPL_NAME(deque)
  324. #elif defined (_STLP_DEBUG)
  325. # define deque _STLP_NON_DBG_NAME(deque)
  326. #else
  327. _STLP_MOVE_TO_STD_NAMESPACE
  328. #endif
  329. template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) >
  330. class deque : protected _STLP_PRIV _Deque_base<_Tp, _Alloc>
  331. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (deque)
  332. , public __stlport_class<deque<_Tp, _Alloc> >
  333. #endif
  334. {
  335. typedef _STLP_PRIV _Deque_base<_Tp, _Alloc> _Base;
  336. typedef deque<_Tp, _Alloc> _Self;
  337. public: // Basic types
  338. typedef _Tp value_type;
  339. typedef value_type* pointer;
  340. typedef const value_type* const_pointer;
  341. typedef value_type& reference;
  342. typedef const value_type& const_reference;
  343. typedef size_t size_type;
  344. typedef ptrdiff_t difference_type;
  345. typedef random_access_iterator_tag _Iterator_category;
  346. _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
  347. typedef typename _Base::allocator_type allocator_type;
  348. public: // Iterators
  349. typedef typename _Base::iterator iterator;
  350. typedef typename _Base::const_iterator const_iterator;
  351. _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
  352. protected: // Internal typedefs
  353. typedef pointer* _Map_pointer;
  354. #if defined (_STLP_NO_MOVE_SEMANTIC)
  355. typedef __false_type _Movable;
  356. #endif
  357. public: // Basic accessors
  358. iterator begin() { return this->_M_start; }
  359. iterator end() { return this->_M_finish; }
  360. const_iterator begin() const { return const_iterator(this->_M_start); }
  361. const_iterator end() const { return const_iterator(this->_M_finish); }
  362. reverse_iterator rbegin() { return reverse_iterator(this->_M_finish); }
  363. reverse_iterator rend() { return reverse_iterator(this->_M_start); }
  364. const_reverse_iterator rbegin() const
  365. { return const_reverse_iterator(this->_M_finish); }
  366. const_reverse_iterator rend() const
  367. { return const_reverse_iterator(this->_M_start); }
  368. reference operator[](size_type __n)
  369. { return this->_M_start[difference_type(__n)]; }
  370. const_reference operator[](size_type __n) const
  371. { return this->_M_start[difference_type(__n)]; }
  372. void _M_range_check(size_type __n) const {
  373. if (__n >= this->size())
  374. __stl_throw_out_of_range("deque");
  375. }
  376. reference at(size_type __n)
  377. { _M_range_check(__n); return (*this)[__n]; }
  378. const_reference at(size_type __n) const
  379. { _M_range_check(__n); return (*this)[__n]; }
  380. reference front() { return *this->_M_start; }
  381. reference back() {
  382. iterator __tmp = this->_M_finish;
  383. --__tmp;
  384. return *__tmp;
  385. }
  386. const_reference front() const { return *this->_M_start; }
  387. const_reference back() const {
  388. const_iterator __tmp = this->_M_finish;
  389. --__tmp;
  390. return *__tmp;
  391. }
  392. size_type size() const { return this->_M_finish - this->_M_start; }
  393. size_type max_size() const { return size_type(-1); }
  394. bool empty() const { return this->_M_finish == this->_M_start; }
  395. allocator_type get_allocator() const { return this->_M_map_size; }
  396. public: // Constructor, destructor.
  397. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  398. explicit deque(const allocator_type& __a = allocator_type())
  399. #else
  400. deque()
  401. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(allocator_type(), 0) {}
  402. deque(const allocator_type& __a)
  403. #endif
  404. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(__a, 0) {}
  405. deque(const _Self& __x)
  406. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(__x.get_allocator(), __x.size())
  407. { _STLP_PRIV __ucopy(__x.begin(), __x.end(), this->_M_start); }
  408. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  409. private:
  410. void _M_initialize(size_type __n, const value_type& __val = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
  411. typedef typename _TrivialInit<_Tp>::_Ret _TrivialInit;
  412. _M_fill_initialize(__val, _TrivialInit());
  413. }
  414. public:
  415. explicit deque(size_type __n)
  416. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(allocator_type(), __n)
  417. { _M_initialize(__n); }
  418. deque(size_type __n, const value_type& __val, const allocator_type& __a = allocator_type())
  419. #else
  420. explicit deque(size_type __n)
  421. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(allocator_type(), __n) {
  422. typedef typename _TrivialInit<_Tp>::_Ret _TrivialInit;
  423. _M_fill_initialize(_STLP_DEFAULT_CONSTRUCTED(_Tp), _TrivialInit());
  424. }
  425. deque(size_type __n, const value_type& __val)
  426. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(allocator_type(), __n)
  427. { _M_fill_initialize(__val, __false_type()); }
  428. deque(size_type __n, const value_type& __val, const allocator_type& __a)
  429. #endif
  430. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(__a, __n)
  431. { _M_fill_initialize(__val, __false_type()); }
  432. #if defined (_STLP_MEMBER_TEMPLATES)
  433. protected:
  434. template <class _Integer>
  435. void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type&) {
  436. this->_M_initialize_map(__n);
  437. _M_fill_initialize(__x, __false_type());
  438. }
  439. template <class _InputIter>
  440. void _M_initialize_dispatch(_InputIter __first, _InputIter __last,
  441. const __false_type&) {
  442. _M_range_initialize(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
  443. }
  444. public:
  445. // Check whether it's an integral type. If so, it's not an iterator.
  446. template <class _InputIterator>
  447. deque(_InputIterator __first, _InputIterator __last,
  448. const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
  449. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(__a) {
  450. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  451. _M_initialize_dispatch(__first, __last, _Integral());
  452. }
  453. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  454. template <class _InputIterator>
  455. deque(_InputIterator __first, _InputIterator __last)
  456. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(allocator_type()) {
  457. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  458. _M_initialize_dispatch(__first, __last, _Integral());
  459. }
  460. # endif
  461. #else
  462. deque(const value_type* __first, const value_type* __last,
  463. const allocator_type& __a = allocator_type() )
  464. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(__a, __last - __first)
  465. { _STLP_PRIV __ucopy(__first, __last, this->_M_start); }
  466. deque(const_iterator __first, const_iterator __last,
  467. const allocator_type& __a = allocator_type() )
  468. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(__a, __last - __first)
  469. { _STLP_PRIV __ucopy(__first, __last, this->_M_start); }
  470. #endif /* _STLP_MEMBER_TEMPLATES */
  471. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  472. deque(__move_source<_Self> src)
  473. : _STLP_PRIV _Deque_base<_Tp, _Alloc>(__move_source<_Base>(src.get()))
  474. {}
  475. #endif
  476. ~deque()
  477. { _STLP_STD::_Destroy_Range(this->_M_start, this->_M_finish); }
  478. _Self& operator= (const _Self& __x);
  479. void swap(_Self& __x) {
  480. _STLP_STD::swap(this->_M_start, __x._M_start);
  481. _STLP_STD::swap(this->_M_finish, __x._M_finish);
  482. this->_M_map.swap(__x._M_map);
  483. this->_M_map_size.swap(__x._M_map_size);
  484. }
  485. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  486. void _M_swap_workaround(_Self& __x) { swap(__x); }
  487. #endif
  488. public:
  489. // assign(), a generalized assignment member function. Two
  490. // versions: one that takes a count, and one that takes a range.
  491. // The range version is a member template, so we dispatch on whether
  492. // or not the type is an integer.
  493. void _M_fill_assign(size_type __n, const _Tp& __val) {
  494. if (__n > size()) {
  495. _STLP_STD::fill(begin(), end(), __val);
  496. insert(end(), __n - size(), __val);
  497. }
  498. else {
  499. erase(begin() + __n, end());
  500. _STLP_STD::fill(begin(), end(), __val);
  501. }
  502. }
  503. void assign(size_type __n, const _Tp& __val) {
  504. _M_fill_assign(__n, __val);
  505. }
  506. #if defined (_STLP_MEMBER_TEMPLATES)
  507. template <class _InputIterator>
  508. void assign(_InputIterator __first, _InputIterator __last) {
  509. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  510. _M_assign_dispatch(__first, __last, _Integral());
  511. }
  512. private: // helper functions for assign()
  513. template <class _Integer>
  514. void _M_assign_dispatch(_Integer __n, _Integer __val,
  515. const __true_type& /*_IsIntegral*/)
  516. { _M_fill_assign((size_type) __n, (_Tp) __val); }
  517. template <class _InputIterator>
  518. void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
  519. const __false_type& /*_IsIntegral*/) {
  520. _M_assign_aux(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
  521. }
  522. template <class _InputIter>
  523. void _M_assign_aux(_InputIter __first, _InputIter __last, const input_iterator_tag &) {
  524. iterator __cur = begin();
  525. for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
  526. *__cur = *__first;
  527. if (__first == __last)
  528. erase(__cur, end());
  529. else
  530. insert(end(), __first, __last);
  531. }
  532. template <class _ForwardIterator>
  533. void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
  534. const forward_iterator_tag &) {
  535. #else
  536. void assign(const value_type *__first, const value_type *__last) {
  537. size_type __size = size();
  538. size_type __len = __last - __first;
  539. if (__len > __size) {
  540. const value_type *__mid = __first + __size;
  541. _STLP_STD::copy(__first, __mid, begin());
  542. insert(end(), __mid, __last);
  543. }
  544. else {
  545. erase(_STLP_STD::copy(__first, __last, begin()), end());
  546. }
  547. }
  548. void assign(const_iterator __first, const_iterator __last) {
  549. typedef const_iterator _ForwardIterator;
  550. #endif /* _STLP_MEMBER_TEMPLATES */
  551. size_type __len = _STLP_STD::distance(__first, __last);
  552. if (__len > size()) {
  553. _ForwardIterator __mid = __first;
  554. _STLP_STD::advance(__mid, size());
  555. _STLP_STD::copy(__first, __mid, begin());
  556. insert(end(), __mid, __last);
  557. }
  558. else {
  559. erase(_STLP_STD::copy(__first, __last, begin()), end());
  560. }
  561. }
  562. public: // push_* and pop_*
  563. #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
  564. void push_back(const value_type& __t = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
  565. #else
  566. void push_back(const value_type& __t) {
  567. #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  568. if (this->_M_finish._M_cur != this->_M_finish._M_last - 1) {
  569. _Copy_Construct(this->_M_finish._M_cur, __t);
  570. ++this->_M_finish._M_cur;
  571. }
  572. else
  573. _M_push_back_aux_v(__t);
  574. }
  575. #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
  576. void push_front(const value_type& __t = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
  577. #else
  578. void push_front(const value_type& __t) {
  579. #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  580. if (this->_M_start._M_cur != this->_M_start._M_first) {
  581. _Copy_Construct(this->_M_start._M_cur - 1, __t);
  582. --this->_M_start._M_cur;
  583. }
  584. else
  585. _M_push_front_aux_v(__t);
  586. }
  587. #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
  588. void push_back() {
  589. if (this->_M_finish._M_cur != this->_M_finish._M_last - 1) {
  590. _STLP_STD::_Construct(this->_M_finish._M_cur);
  591. ++this->_M_finish._M_cur;
  592. }
  593. else
  594. _M_push_back_aux();
  595. }
  596. void push_front() {
  597. if (this->_M_start._M_cur != this->_M_start._M_first) {
  598. _STLP_STD::_Construct(this->_M_start._M_cur - 1);
  599. --this->_M_start._M_cur;
  600. }
  601. else
  602. _M_push_front_aux();
  603. }
  604. #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  605. void pop_back() {
  606. if (this->_M_finish._M_cur != this->_M_finish._M_first) {
  607. --this->_M_finish._M_cur;
  608. _STLP_STD::_Destroy(this->_M_finish._M_cur);
  609. }
  610. else {
  611. _M_pop_back_aux();
  612. _STLP_STD::_Destroy(this->_M_finish._M_cur);
  613. }
  614. }
  615. void pop_front() {
  616. _STLP_STD::_Destroy(this->_M_start._M_cur);
  617. _M_pop_front_aux();
  618. }
  619. public: // Insert
  620. #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
  621. iterator insert(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
  622. #else
  623. iterator insert(iterator __pos, const value_type& __x) {
  624. #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  625. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  626. typedef typename __move_traits<_Tp>::implemented _Movable;
  627. #endif
  628. if (__pos._M_cur == this->_M_start._M_cur) {
  629. push_front(__x);
  630. return this->_M_start;
  631. }
  632. else if (__pos._M_cur == this->_M_finish._M_cur) {
  633. push_back(__x);
  634. iterator __tmp = this->_M_finish;
  635. --__tmp;
  636. return __tmp;
  637. }
  638. else {
  639. return _M_fill_insert_aux(__pos, 1, __x, _Movable());
  640. }
  641. }
  642. #if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
  643. iterator insert(iterator __pos)
  644. { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
  645. #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  646. void insert(iterator __pos, size_type __n, const value_type& __x)
  647. { _M_fill_insert(__pos, __n, __x); }
  648. protected:
  649. iterator _M_fill_insert_aux(iterator __pos, size_type __n, const value_type& __x, const __true_type& /*_Movable*/);
  650. iterator _M_fill_insert_aux(iterator __pos, size_type __n, const value_type& __x, const __false_type& /*_Movable*/);
  651. void _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
  652. #if defined (_STLP_MEMBER_TEMPLATES)
  653. template <class _Integer>
  654. void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
  655. const __true_type& /*_IsIntegral*/) {
  656. _M_fill_insert(__pos, (size_type) __n, (value_type) __x);
  657. }
  658. template <class _InputIterator>
  659. void _M_insert_dispatch(iterator __pos,
  660. _InputIterator __first, _InputIterator __last,
  661. const __false_type& /*_IsIntegral*/) {
  662. _M_insert(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
  663. }
  664. public:
  665. // Check whether it's an integral type. If so, it's not an iterator.
  666. template <class _InputIterator>
  667. void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
  668. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  669. _M_insert_dispatch(__pos, __first, __last, _Integral());
  670. }
  671. #else /* _STLP_MEMBER_TEMPLATES */
  672. void _M_insert_range_aux(iterator __pos,
  673. const value_type* __first, const value_type* __last,
  674. size_type __n, const __true_type& /*_Movable*/);
  675. void _M_insert_range_aux(iterator __pos,
  676. const value_type* __first, const value_type* __last,
  677. size_type __n, const __false_type& /*_Movable*/);
  678. void _M_insert_range_aux(iterator __pos,
  679. const_iterator __first, const_iterator __last,
  680. size_type __n, const __true_type& /*_Movable*/);
  681. void _M_insert_range_aux(iterator __pos,
  682. const_iterator __first, const_iterator __last,
  683. size_type __n, const __false_type& /*_Movable*/);
  684. public:
  685. void insert(iterator __pos,
  686. const value_type* __first, const value_type* __last);
  687. void insert(iterator __pos,
  688. const_iterator __first, const_iterator __last);
  689. #endif /* _STLP_MEMBER_TEMPLATES */
  690. public:
  691. #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
  692. void resize(size_type __new_size,
  693. const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
  694. #else
  695. void resize(size_type __new_size, const value_type& __x) {
  696. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  697. const size_type __len = size();
  698. if (__new_size < __len)
  699. erase(this->_M_start + __new_size, this->_M_finish);
  700. else
  701. insert(this->_M_finish, __new_size - __len, __x);
  702. }
  703. #if defined (_STLP_DONT_SUP_DFLT_PARAM)
  704. void resize(size_type __new_size)
  705. { resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
  706. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  707. protected:
  708. iterator _M_erase(iterator __pos, const __true_type& /*_Movable*/);
  709. iterator _M_erase(iterator __pos, const __false_type& /*_Movable*/);
  710. iterator _M_erase(iterator __first, iterator __last, const __true_type& /*_Movable*/);
  711. iterator _M_erase(iterator __first, iterator __last, const __false_type& /*_Movable*/);
  712. public: // Erase
  713. iterator erase(iterator __pos) {
  714. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  715. typedef typename __move_traits<_Tp>::implemented _Movable;
  716. #endif
  717. return _M_erase(__pos, _Movable());
  718. }
  719. iterator erase(iterator __first, iterator __last) {
  720. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  721. typedef typename __move_traits<_Tp>::implemented _Movable;
  722. #endif
  723. if (__first == this->_M_start && __last == this->_M_finish) {
  724. clear();
  725. return this->_M_finish;
  726. }
  727. else {
  728. if (__first == __last)
  729. return __first;
  730. return _M_erase(__first, __last, _Movable());
  731. }
  732. }
  733. void clear();
  734. protected: // Internal construction/destruction
  735. void _M_fill_initialize(const value_type& __val, const __true_type& /*_TrivialInit*/)
  736. {}
  737. void _M_fill_initialize(const value_type& __val, const __false_type& /*_TrivialInit*/);
  738. #if defined (_STLP_MEMBER_TEMPLATES)
  739. template <class _InputIterator>
  740. void _M_range_initialize(_InputIterator __first, _InputIterator __last,
  741. const input_iterator_tag &) {
  742. this->_M_initialize_map(0);
  743. _STLP_TRY {
  744. for ( ; __first != __last; ++__first)
  745. push_back(*__first);
  746. }
  747. _STLP_UNWIND(clear())
  748. }
  749. template <class _ForwardIterator>
  750. void _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
  751. const forward_iterator_tag &) {
  752. size_type __n = _STLP_STD::distance(__first, __last);
  753. this->_M_initialize_map(__n);
  754. _Map_pointer __cur_node = this->_M_start._M_node;
  755. _STLP_TRY {
  756. for (; __cur_node < this->_M_finish._M_node; ++__cur_node) {
  757. _ForwardIterator __mid = __first;
  758. _STLP_STD::advance(__mid, this->buffer_size());
  759. _STLP_STD::uninitialized_copy(__first, __mid, *__cur_node);
  760. __first = __mid;
  761. }
  762. _STLP_STD::uninitialized_copy(__first, __last, this->_M_finish._M_first);
  763. }
  764. _STLP_UNWIND(_STLP_STD::_Destroy_Range(this->_M_start, iterator(*__cur_node, __cur_node)))
  765. }
  766. #endif /* _STLP_MEMBER_TEMPLATES */
  767. protected: // Internal push_* and pop_*
  768. void _M_push_back_aux_v(const value_type&);
  769. void _M_push_front_aux_v(const value_type&);
  770. #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
  771. void _M_push_back_aux();
  772. void _M_push_front_aux();
  773. #endif /*_STLP_DONT_SUP_DFLT_PARAM !_STLP_NO_ANACHRONISMS*/
  774. void _M_pop_back_aux();
  775. void _M_pop_front_aux();
  776. protected: // Internal insert functions
  777. #if defined (_STLP_MEMBER_TEMPLATES)
  778. template <class _InputIterator>
  779. void _M_insert(iterator __pos,
  780. _InputIterator __first,
  781. _InputIterator __last,
  782. const input_iterator_tag &) {
  783. _STLP_STD::copy(__first, __last, inserter(*this, __pos));
  784. }
  785. template <class _ForwardIterator>
  786. void _M_insert(iterator __pos,
  787. _ForwardIterator __first, _ForwardIterator __last,
  788. const forward_iterator_tag &) {
  789. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  790. typedef typename __move_traits<_Tp>::implemented _Movable;
  791. #endif
  792. size_type __n = _STLP_STD::distance(__first, __last);
  793. if (__pos._M_cur == this->_M_start._M_cur) {
  794. iterator __new_start = _M_reserve_elements_at_front(__n);
  795. _STLP_TRY {
  796. uninitialized_copy(__first, __last, __new_start);
  797. this->_M_start = __new_start;
  798. }
  799. _STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node))
  800. }
  801. else if (__pos._M_cur == this->_M_finish._M_cur) {
  802. iterator __new_finish = _M_reserve_elements_at_back(__n);
  803. _STLP_TRY {
  804. uninitialized_copy(__first, __last, this->_M_finish);
  805. this->_M_finish = __new_finish;
  806. }
  807. _STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1, __new_finish._M_node + 1))
  808. }
  809. else
  810. _M_insert_range_aux(__pos, __first, __last, __n, _Movable());
  811. }
  812. template <class _ForwardIterator>
  813. void _M_insert_range_aux(iterator __pos,
  814. _ForwardIterator __first, _ForwardIterator __last,
  815. size_type __n, const __true_type& /*_Movable*/) {
  816. const difference_type __elemsbefore = __pos - this->_M_start;
  817. size_type __length = size();
  818. if (__elemsbefore <= difference_type(__length / 2)) {
  819. iterator __new_start = _M_reserve_elements_at_front(__n);
  820. __pos = this->_M_start + __elemsbefore;
  821. _STLP_TRY {
  822. iterator __dst = __new_start;
  823. iterator __src = this->_M_start;
  824. for (; __src != __pos; ++__dst, ++__src) {
  825. _STLP_STD::_Move_Construct(&(*__dst), *__src);
  826. _STLP_STD::_Destroy_Moved(&(*__src));
  827. }
  828. this->_M_start = __new_start;
  829. uninitialized_copy(__first, __last, __dst);
  830. }
  831. _STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node))
  832. }
  833. else {
  834. iterator __new_finish = _M_reserve_elements_at_back(__n);
  835. const difference_type __elemsafter = difference_type(__length) - __elemsbefore;
  836. __pos = this->_M_finish - __elemsafter;
  837. _STLP_TRY {
  838. iterator __dst = __new_finish;
  839. iterator __src = this->_M_finish;
  840. for (--__src, --__dst; __src >= __pos; --__src, --__dst) {
  841. _STLP_STD::_Move_Construct(&(*__dst), *__src);
  842. _STLP_STD::_Destroy_Moved(&(*__src));
  843. }
  844. this->_M_finish = __new_finish;
  845. uninitialized_copy(__first, __last, __pos);
  846. }
  847. _STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1, __new_finish._M_node + 1))
  848. }
  849. }
  850. template <class _ForwardIterator>
  851. void _M_insert_range_aux(iterator __pos,
  852. _ForwardIterator __first, _ForwardIterator __last,
  853. size_type __n, const __false_type& /*_Movable*/) {
  854. const difference_type __elemsbefore = __pos - this->_M_start;
  855. size_type __length = size();
  856. if (__elemsbefore <= difference_type(__length / 2)) {
  857. iterator __new_start = _M_reserve_elements_at_front(__n);
  858. iterator __old_start = this->_M_start;
  859. __pos = this->_M_start + __elemsbefore;
  860. _STLP_TRY {
  861. if (__elemsbefore >= difference_type(__n)) {
  862. iterator __start_n = this->_M_start + difference_type(__n);
  863. _STLP_STD::uninitialized_copy(this->_M_start, __start_n, __new_start);
  864. this->_M_start = __new_start;
  865. _STLP_STD::copy(__start_n, __pos, __old_start);
  866. _STLP_STD::copy(__first, __last, __pos - difference_type(__n));
  867. }
  868. else {
  869. _ForwardIterator __mid = __first;
  870. _STLP_STD::advance(__mid, difference_type(__n) - __elemsbefore);
  871. _STLP_PRIV __uninitialized_copy_copy(this->_M_start, __pos, __first, __mid, __new_start);
  872. this->_M_start = __new_start;
  873. _STLP_STD::copy(__mid, __last, __old_start);
  874. }
  875. }
  876. _STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node))
  877. }
  878. else {
  879. iterator __new_finish = _M_reserve_elements_at_back(__n);
  880. iterator __old_finish = this->_M_finish;
  881. const difference_type __elemsafter = difference_type(__length) - __elemsbefore;
  882. __pos = this->_M_finish - __elemsafter;
  883. _STLP_TRY {
  884. if (__elemsafter > difference_type(__n)) {
  885. iterator __finish_n = this->_M_finish - difference_type(__n);
  886. _STLP_STD::uninitialized_copy(__finish_n, this->_M_finish, this->_M_finish);
  887. this->_M_finish = __new_finish;
  888. _STLP_STD::copy_backward(__pos, __finish_n, __old_finish);
  889. _STLP_STD::copy(__first, __last, __pos);
  890. }
  891. else {
  892. _ForwardIterator __mid = __first;
  893. _STLP_STD::advance(__mid, __elemsafter);
  894. _STLP_PRIV __uninitialized_copy_copy(__mid, __last, __pos, this->_M_finish, this->_M_finish);
  895. this->_M_finish = __new_finish;
  896. _STLP_STD::copy(__first, __mid, __pos);
  897. }
  898. }
  899. _STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1, __new_finish._M_node + 1))
  900. }
  901. }
  902. #endif /* _STLP_MEMBER_TEMPLATES */
  903. iterator _M_reserve_elements_at_front(size_type __n) {
  904. size_type __vacancies = this->_M_start._M_cur - this->_M_start._M_first;
  905. if (__n > __vacancies)
  906. _M_new_elements_at_front(__n - __vacancies);
  907. return this->_M_start - difference_type(__n);
  908. }
  909. iterator _M_reserve_elements_at_back(size_type __n) {
  910. size_type __vacancies = (this->_M_finish._M_last - this->_M_finish._M_cur) - 1;
  911. if (__n > __vacancies)
  912. _M_new_elements_at_back(__n - __vacancies);
  913. return this->_M_finish + difference_type(__n);
  914. }
  915. void _M_new_elements_at_front(size_type __new_elements);
  916. void _M_new_elements_at_back(size_type __new_elements);
  917. protected: // Allocation of _M_map and nodes
  918. // Makes sure the _M_map has space for new nodes. Does not actually
  919. // add the nodes. Can invalidate _M_map pointers. (And consequently,
  920. // deque iterators.)
  921. void _M_reserve_map_at_back (size_type __nodes_to_add = 1) {
  922. if (__nodes_to_add + 1 > this->_M_map_size._M_data - (this->_M_finish._M_node - this->_M_map._M_data))
  923. _M_reallocate_map(__nodes_to_add, false);
  924. }
  925. void _M_reserve_map_at_front (size_type __nodes_to_add = 1) {
  926. if (__nodes_to_add > size_type(this->_M_start._M_node - this->_M_map._M_data))
  927. _M_reallocate_map(__nodes_to_add, true);
  928. }
  929. void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
  930. };
  931. #if defined (deque)
  932. # undef deque
  933. _STLP_MOVE_TO_STD_NAMESPACE
  934. #endif
  935. _STLP_END_NAMESPACE
  936. #if !defined (_STLP_LINK_TIME_INSTANTIATION)
  937. # include <stl/_deque.c>
  938. #endif
  939. #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
  940. # include <stl/pointers/_deque.h>
  941. #endif
  942. #if defined (_STLP_DEBUG)
  943. # include <stl/debug/_deque.h>
  944. #endif
  945. _STLP_BEGIN_NAMESPACE
  946. #define _STLP_TEMPLATE_CONTAINER deque<_Tp, _Alloc>
  947. #define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc>
  948. #include <stl/_relops_cont.h>
  949. #undef _STLP_TEMPLATE_CONTAINER
  950. #undef _STLP_TEMPLATE_HEADER
  951. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_MOVE_SEMANTIC)
  952. template <class _Tp, class _Alloc>
  953. struct __move_traits<deque<_Tp, _Alloc> > {
  954. typedef __true_type implemented;
  955. typedef typename __move_traits<_Alloc>::complete complete;
  956. };
  957. #endif
  958. _STLP_END_NAMESPACE
  959. #endif /* _STLP_INTERNAL_DEQUE_H */
  960. // Local Variables:
  961. // mode:C++
  962. // End: