re PR libstdc++/54577 (deque<T>::erase() still takes iterator instead of const_iterator)
[gcc.git] / libstdc++-v3 / include / bits / stl_deque.h
1 // Deque implementation -*- C++ -*-
2
3 // Copyright (C) 2001-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 /*
26 *
27 * Copyright (c) 1994
28 * Hewlett-Packard Company
29 *
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
37 *
38 *
39 * Copyright (c) 1997
40 * Silicon Graphics Computer Systems, Inc.
41 *
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
49 */
50
51 /** @file bits/stl_deque.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{deque}
54 */
55
56 #ifndef _STL_DEQUE_H
57 #define _STL_DEQUE_H 1
58
59 #include <bits/concept_check.h>
60 #include <bits/stl_iterator_base_types.h>
61 #include <bits/stl_iterator_base_funcs.h>
62 #if __cplusplus >= 201103L
63 #include <initializer_list>
64 #endif
65
66 namespace std _GLIBCXX_VISIBILITY(default)
67 {
68 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
69
70 /**
71 * @brief This function controls the size of memory nodes.
72 * @param __size The size of an element.
73 * @return The number (not byte size) of elements per node.
74 *
75 * This function started off as a compiler kludge from SGI, but
76 * seems to be a useful wrapper around a repeated constant
77 * expression. The @b 512 is tunable (and no other code needs to
78 * change), but no investigation has been done since inheriting the
79 * SGI code. Touch _GLIBCXX_DEQUE_BUF_SIZE only if you know what
80 * you are doing, however: changing it breaks the binary
81 * compatibility!!
82 */
83
84 #ifndef _GLIBCXX_DEQUE_BUF_SIZE
85 #define _GLIBCXX_DEQUE_BUF_SIZE 512
86 #endif
87
88 inline size_t
89 __deque_buf_size(size_t __size)
90 { return (__size < _GLIBCXX_DEQUE_BUF_SIZE
91 ? size_t(_GLIBCXX_DEQUE_BUF_SIZE / __size) : size_t(1)); }
92
93
94 /**
95 * @brief A deque::iterator.
96 *
97 * Quite a bit of intelligence here. Much of the functionality of
98 * deque is actually passed off to this class. A deque holds two
99 * of these internally, marking its valid range. Access to
100 * elements is done as offsets of either of those two, relying on
101 * operator overloading in this class.
102 *
103 * All the functions are op overloads except for _M_set_node.
104 */
105 template<typename _Tp, typename _Ref, typename _Ptr>
106 struct _Deque_iterator
107 {
108 typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator;
109 typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
110
111 static size_t _S_buffer_size()
112 { return __deque_buf_size(sizeof(_Tp)); }
113
114 typedef std::random_access_iterator_tag iterator_category;
115 typedef _Tp value_type;
116 typedef _Ptr pointer;
117 typedef _Ref reference;
118 typedef size_t size_type;
119 typedef ptrdiff_t difference_type;
120 typedef _Tp** _Map_pointer;
121 typedef _Deque_iterator _Self;
122
123 _Tp* _M_cur;
124 _Tp* _M_first;
125 _Tp* _M_last;
126 _Map_pointer _M_node;
127
128 _Deque_iterator(_Tp* __x, _Map_pointer __y)
129 : _M_cur(__x), _M_first(*__y),
130 _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
131
132 _Deque_iterator()
133 : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) { }
134
135 _Deque_iterator(const iterator& __x)
136 : _M_cur(__x._M_cur), _M_first(__x._M_first),
137 _M_last(__x._M_last), _M_node(__x._M_node) { }
138
139 iterator
140 _M_const_cast() const
141 { return iterator(_M_cur, _M_node); }
142
143 reference
144 operator*() const
145 { return *_M_cur; }
146
147 pointer
148 operator->() const
149 { return _M_cur; }
150
151 _Self&
152 operator++()
153 {
154 ++_M_cur;
155 if (_M_cur == _M_last)
156 {
157 _M_set_node(_M_node + 1);
158 _M_cur = _M_first;
159 }
160 return *this;
161 }
162
163 _Self
164 operator++(int)
165 {
166 _Self __tmp = *this;
167 ++*this;
168 return __tmp;
169 }
170
171 _Self&
172 operator--()
173 {
174 if (_M_cur == _M_first)
175 {
176 _M_set_node(_M_node - 1);
177 _M_cur = _M_last;
178 }
179 --_M_cur;
180 return *this;
181 }
182
183 _Self
184 operator--(int)
185 {
186 _Self __tmp = *this;
187 --*this;
188 return __tmp;
189 }
190
191 _Self&
192 operator+=(difference_type __n)
193 {
194 const difference_type __offset = __n + (_M_cur - _M_first);
195 if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
196 _M_cur += __n;
197 else
198 {
199 const difference_type __node_offset =
200 __offset > 0 ? __offset / difference_type(_S_buffer_size())
201 : -difference_type((-__offset - 1)
202 / _S_buffer_size()) - 1;
203 _M_set_node(_M_node + __node_offset);
204 _M_cur = _M_first + (__offset - __node_offset
205 * difference_type(_S_buffer_size()));
206 }
207 return *this;
208 }
209
210 _Self
211 operator+(difference_type __n) const
212 {
213 _Self __tmp = *this;
214 return __tmp += __n;
215 }
216
217 _Self&
218 operator-=(difference_type __n)
219 { return *this += -__n; }
220
221 _Self
222 operator-(difference_type __n) const
223 {
224 _Self __tmp = *this;
225 return __tmp -= __n;
226 }
227
228 reference
229 operator[](difference_type __n) const
230 { return *(*this + __n); }
231
232 /**
233 * Prepares to traverse new_node. Sets everything except
234 * _M_cur, which should therefore be set by the caller
235 * immediately afterwards, based on _M_first and _M_last.
236 */
237 void
238 _M_set_node(_Map_pointer __new_node)
239 {
240 _M_node = __new_node;
241 _M_first = *__new_node;
242 _M_last = _M_first + difference_type(_S_buffer_size());
243 }
244 };
245
246 // Note: we also provide overloads whose operands are of the same type in
247 // order to avoid ambiguous overload resolution when std::rel_ops operators
248 // are in scope (for additional details, see libstdc++/3628)
249 template<typename _Tp, typename _Ref, typename _Ptr>
250 inline bool
251 operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
252 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
253 { return __x._M_cur == __y._M_cur; }
254
255 template<typename _Tp, typename _RefL, typename _PtrL,
256 typename _RefR, typename _PtrR>
257 inline bool
258 operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
259 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
260 { return __x._M_cur == __y._M_cur; }
261
262 template<typename _Tp, typename _Ref, typename _Ptr>
263 inline bool
264 operator!=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
265 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
266 { return !(__x == __y); }
267
268 template<typename _Tp, typename _RefL, typename _PtrL,
269 typename _RefR, typename _PtrR>
270 inline bool
271 operator!=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
272 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
273 { return !(__x == __y); }
274
275 template<typename _Tp, typename _Ref, typename _Ptr>
276 inline bool
277 operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
278 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
279 { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
280 : (__x._M_node < __y._M_node); }
281
282 template<typename _Tp, typename _RefL, typename _PtrL,
283 typename _RefR, typename _PtrR>
284 inline bool
285 operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
286 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
287 { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
288 : (__x._M_node < __y._M_node); }
289
290 template<typename _Tp, typename _Ref, typename _Ptr>
291 inline bool
292 operator>(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
293 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
294 { return __y < __x; }
295
296 template<typename _Tp, typename _RefL, typename _PtrL,
297 typename _RefR, typename _PtrR>
298 inline bool
299 operator>(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
300 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
301 { return __y < __x; }
302
303 template<typename _Tp, typename _Ref, typename _Ptr>
304 inline bool
305 operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
306 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
307 { return !(__y < __x); }
308
309 template<typename _Tp, typename _RefL, typename _PtrL,
310 typename _RefR, typename _PtrR>
311 inline bool
312 operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
313 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
314 { return !(__y < __x); }
315
316 template<typename _Tp, typename _Ref, typename _Ptr>
317 inline bool
318 operator>=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
319 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
320 { return !(__x < __y); }
321
322 template<typename _Tp, typename _RefL, typename _PtrL,
323 typename _RefR, typename _PtrR>
324 inline bool
325 operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
326 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
327 { return !(__x < __y); }
328
329 // _GLIBCXX_RESOLVE_LIB_DEFECTS
330 // According to the resolution of DR179 not only the various comparison
331 // operators but also operator- must accept mixed iterator/const_iterator
332 // parameters.
333 template<typename _Tp, typename _Ref, typename _Ptr>
334 inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
335 operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
336 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
337 {
338 return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
339 (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size())
340 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
341 + (__y._M_last - __y._M_cur);
342 }
343
344 template<typename _Tp, typename _RefL, typename _PtrL,
345 typename _RefR, typename _PtrR>
346 inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
347 operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
348 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
349 {
350 return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
351 (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size())
352 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
353 + (__y._M_last - __y._M_cur);
354 }
355
356 template<typename _Tp, typename _Ref, typename _Ptr>
357 inline _Deque_iterator<_Tp, _Ref, _Ptr>
358 operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
359 { return __x + __n; }
360
361 template<typename _Tp>
362 void
363 fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
364 const _Deque_iterator<_Tp, _Tp&, _Tp*>&, const _Tp&);
365
366 template<typename _Tp>
367 _Deque_iterator<_Tp, _Tp&, _Tp*>
368 copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
369 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
370 _Deque_iterator<_Tp, _Tp&, _Tp*>);
371
372 template<typename _Tp>
373 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
374 copy(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
375 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
376 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
377 { return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
378 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
379 __result); }
380
381 template<typename _Tp>
382 _Deque_iterator<_Tp, _Tp&, _Tp*>
383 copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
384 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
385 _Deque_iterator<_Tp, _Tp&, _Tp*>);
386
387 template<typename _Tp>
388 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
389 copy_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
390 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
391 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
392 { return std::copy_backward(_Deque_iterator<_Tp,
393 const _Tp&, const _Tp*>(__first),
394 _Deque_iterator<_Tp,
395 const _Tp&, const _Tp*>(__last),
396 __result); }
397
398 #if __cplusplus >= 201103L
399 template<typename _Tp>
400 _Deque_iterator<_Tp, _Tp&, _Tp*>
401 move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
402 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
403 _Deque_iterator<_Tp, _Tp&, _Tp*>);
404
405 template<typename _Tp>
406 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
407 move(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
408 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
409 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
410 { return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
411 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
412 __result); }
413
414 template<typename _Tp>
415 _Deque_iterator<_Tp, _Tp&, _Tp*>
416 move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
417 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
418 _Deque_iterator<_Tp, _Tp&, _Tp*>);
419
420 template<typename _Tp>
421 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
422 move_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
423 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
424 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
425 { return std::move_backward(_Deque_iterator<_Tp,
426 const _Tp&, const _Tp*>(__first),
427 _Deque_iterator<_Tp,
428 const _Tp&, const _Tp*>(__last),
429 __result); }
430 #endif
431
432 /**
433 * Deque base class. This class provides the unified face for %deque's
434 * allocation. This class's constructor and destructor allocate and
435 * deallocate (but do not initialize) storage. This makes %exception
436 * safety easier.
437 *
438 * Nothing in this class ever constructs or destroys an actual Tp element.
439 * (Deque handles that itself.) Only/All memory management is performed
440 * here.
441 */
442 template<typename _Tp, typename _Alloc>
443 class _Deque_base
444 {
445 public:
446 typedef _Alloc allocator_type;
447
448 allocator_type
449 get_allocator() const _GLIBCXX_NOEXCEPT
450 { return allocator_type(_M_get_Tp_allocator()); }
451
452 typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator;
453 typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
454
455 _Deque_base()
456 : _M_impl()
457 { _M_initialize_map(0); }
458
459 _Deque_base(size_t __num_elements)
460 : _M_impl()
461 { _M_initialize_map(__num_elements); }
462
463 _Deque_base(const allocator_type& __a, size_t __num_elements)
464 : _M_impl(__a)
465 { _M_initialize_map(__num_elements); }
466
467 _Deque_base(const allocator_type& __a)
468 : _M_impl(__a)
469 { }
470
471 #if __cplusplus >= 201103L
472 _Deque_base(_Deque_base&& __x)
473 : _M_impl(std::move(__x._M_get_Tp_allocator()))
474 {
475 _M_initialize_map(0);
476 if (__x._M_impl._M_map)
477 {
478 std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
479 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
480 std::swap(this->_M_impl._M_map, __x._M_impl._M_map);
481 std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size);
482 }
483 }
484 #endif
485
486 ~_Deque_base();
487
488 protected:
489 //This struct encapsulates the implementation of the std::deque
490 //standard container and at the same time makes use of the EBO
491 //for empty allocators.
492 typedef typename _Alloc::template rebind<_Tp*>::other _Map_alloc_type;
493
494 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
495
496 struct _Deque_impl
497 : public _Tp_alloc_type
498 {
499 _Tp** _M_map;
500 size_t _M_map_size;
501 iterator _M_start;
502 iterator _M_finish;
503
504 _Deque_impl()
505 : _Tp_alloc_type(), _M_map(0), _M_map_size(0),
506 _M_start(), _M_finish()
507 { }
508
509 _Deque_impl(const _Tp_alloc_type& __a)
510 : _Tp_alloc_type(__a), _M_map(0), _M_map_size(0),
511 _M_start(), _M_finish()
512 { }
513
514 #if __cplusplus >= 201103L
515 _Deque_impl(_Tp_alloc_type&& __a)
516 : _Tp_alloc_type(std::move(__a)), _M_map(0), _M_map_size(0),
517 _M_start(), _M_finish()
518 { }
519 #endif
520 };
521
522 _Tp_alloc_type&
523 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
524 { return *static_cast<_Tp_alloc_type*>(&this->_M_impl); }
525
526 const _Tp_alloc_type&
527 _M_get_Tp_allocator() const _GLIBCXX_NOEXCEPT
528 { return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); }
529
530 _Map_alloc_type
531 _M_get_map_allocator() const _GLIBCXX_NOEXCEPT
532 { return _Map_alloc_type(_M_get_Tp_allocator()); }
533
534 _Tp*
535 _M_allocate_node()
536 {
537 return _M_impl._Tp_alloc_type::allocate(__deque_buf_size(sizeof(_Tp)));
538 }
539
540 void
541 _M_deallocate_node(_Tp* __p)
542 {
543 _M_impl._Tp_alloc_type::deallocate(__p, __deque_buf_size(sizeof(_Tp)));
544 }
545
546 _Tp**
547 _M_allocate_map(size_t __n)
548 { return _M_get_map_allocator().allocate(__n); }
549
550 void
551 _M_deallocate_map(_Tp** __p, size_t __n)
552 { _M_get_map_allocator().deallocate(__p, __n); }
553
554 protected:
555 void _M_initialize_map(size_t);
556 void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
557 void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
558 enum { _S_initial_map_size = 8 };
559
560 _Deque_impl _M_impl;
561 };
562
563 template<typename _Tp, typename _Alloc>
564 _Deque_base<_Tp, _Alloc>::
565 ~_Deque_base()
566 {
567 if (this->_M_impl._M_map)
568 {
569 _M_destroy_nodes(this->_M_impl._M_start._M_node,
570 this->_M_impl._M_finish._M_node + 1);
571 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
572 }
573 }
574
575 /**
576 * @brief Layout storage.
577 * @param __num_elements The count of T's for which to allocate space
578 * at first.
579 * @return Nothing.
580 *
581 * The initial underlying memory layout is a bit complicated...
582 */
583 template<typename _Tp, typename _Alloc>
584 void
585 _Deque_base<_Tp, _Alloc>::
586 _M_initialize_map(size_t __num_elements)
587 {
588 const size_t __num_nodes = (__num_elements/ __deque_buf_size(sizeof(_Tp))
589 + 1);
590
591 this->_M_impl._M_map_size = std::max((size_t) _S_initial_map_size,
592 size_t(__num_nodes + 2));
593 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
594
595 // For "small" maps (needing less than _M_map_size nodes), allocation
596 // starts in the middle elements and grows outwards. So nstart may be
597 // the beginning of _M_map, but for small maps it may be as far in as
598 // _M_map+3.
599
600 _Tp** __nstart = (this->_M_impl._M_map
601 + (this->_M_impl._M_map_size - __num_nodes) / 2);
602 _Tp** __nfinish = __nstart + __num_nodes;
603
604 __try
605 { _M_create_nodes(__nstart, __nfinish); }
606 __catch(...)
607 {
608 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
609 this->_M_impl._M_map = 0;
610 this->_M_impl._M_map_size = 0;
611 __throw_exception_again;
612 }
613
614 this->_M_impl._M_start._M_set_node(__nstart);
615 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
616 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
617 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
618 + __num_elements
619 % __deque_buf_size(sizeof(_Tp)));
620 }
621
622 template<typename _Tp, typename _Alloc>
623 void
624 _Deque_base<_Tp, _Alloc>::
625 _M_create_nodes(_Tp** __nstart, _Tp** __nfinish)
626 {
627 _Tp** __cur;
628 __try
629 {
630 for (__cur = __nstart; __cur < __nfinish; ++__cur)
631 *__cur = this->_M_allocate_node();
632 }
633 __catch(...)
634 {
635 _M_destroy_nodes(__nstart, __cur);
636 __throw_exception_again;
637 }
638 }
639
640 template<typename _Tp, typename _Alloc>
641 void
642 _Deque_base<_Tp, _Alloc>::
643 _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish)
644 {
645 for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
646 _M_deallocate_node(*__n);
647 }
648
649 /**
650 * @brief A standard container using fixed-size memory allocation and
651 * constant-time manipulation of elements at either end.
652 *
653 * @ingroup sequences
654 *
655 * @tparam _Tp Type of element.
656 * @tparam _Alloc Allocator type, defaults to allocator<_Tp>.
657 *
658 * Meets the requirements of a <a href="tables.html#65">container</a>, a
659 * <a href="tables.html#66">reversible container</a>, and a
660 * <a href="tables.html#67">sequence</a>, including the
661 * <a href="tables.html#68">optional sequence requirements</a>.
662 *
663 * In previous HP/SGI versions of deque, there was an extra template
664 * parameter so users could control the node size. This extension turned
665 * out to violate the C++ standard (it can be detected using template
666 * template parameters), and it was removed.
667 *
668 * Here's how a deque<Tp> manages memory. Each deque has 4 members:
669 *
670 * - Tp** _M_map
671 * - size_t _M_map_size
672 * - iterator _M_start, _M_finish
673 *
674 * map_size is at least 8. %map is an array of map_size
675 * pointers-to-@a nodes. (The name %map has nothing to do with the
676 * std::map class, and @b nodes should not be confused with
677 * std::list's usage of @a node.)
678 *
679 * A @a node has no specific type name as such, but it is referred
680 * to as @a node in this file. It is a simple array-of-Tp. If Tp
681 * is very large, there will be one Tp element per node (i.e., an
682 * @a array of one). For non-huge Tp's, node size is inversely
683 * related to Tp size: the larger the Tp, the fewer Tp's will fit
684 * in a node. The goal here is to keep the total size of a node
685 * relatively small and constant over different Tp's, to improve
686 * allocator efficiency.
687 *
688 * Not every pointer in the %map array will point to a node. If
689 * the initial number of elements in the deque is small, the
690 * /middle/ %map pointers will be valid, and the ones at the edges
691 * will be unused. This same situation will arise as the %map
692 * grows: available %map pointers, if any, will be on the ends. As
693 * new nodes are created, only a subset of the %map's pointers need
694 * to be copied @a outward.
695 *
696 * Class invariants:
697 * - For any nonsingular iterator i:
698 * - i.node points to a member of the %map array. (Yes, you read that
699 * correctly: i.node does not actually point to a node.) The member of
700 * the %map array is what actually points to the node.
701 * - i.first == *(i.node) (This points to the node (first Tp element).)
702 * - i.last == i.first + node_size
703 * - i.cur is a pointer in the range [i.first, i.last). NOTE:
704 * the implication of this is that i.cur is always a dereferenceable
705 * pointer, even if i is a past-the-end iterator.
706 * - Start and Finish are always nonsingular iterators. NOTE: this
707 * means that an empty deque must have one node, a deque with <N
708 * elements (where N is the node buffer size) must have one node, a
709 * deque with N through (2N-1) elements must have two nodes, etc.
710 * - For every node other than start.node and finish.node, every
711 * element in the node is an initialized object. If start.node ==
712 * finish.node, then [start.cur, finish.cur) are initialized
713 * objects, and the elements outside that range are uninitialized
714 * storage. Otherwise, [start.cur, start.last) and [finish.first,
715 * finish.cur) are initialized objects, and [start.first, start.cur)
716 * and [finish.cur, finish.last) are uninitialized storage.
717 * - [%map, %map + map_size) is a valid, non-empty range.
718 * - [start.node, finish.node] is a valid range contained within
719 * [%map, %map + map_size).
720 * - A pointer in the range [%map, %map + map_size) points to an allocated
721 * node if and only if the pointer is in the range
722 * [start.node, finish.node].
723 *
724 * Here's the magic: nothing in deque is @b aware of the discontiguous
725 * storage!
726 *
727 * The memory setup and layout occurs in the parent, _Base, and the iterator
728 * class is entirely responsible for @a leaping from one node to the next.
729 * All the implementation routines for deque itself work only through the
730 * start and finish iterators. This keeps the routines simple and sane,
731 * and we can use other standard algorithms as well.
732 */
733 template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
734 class deque : protected _Deque_base<_Tp, _Alloc>
735 {
736 // concept requirements
737 typedef typename _Alloc::value_type _Alloc_value_type;
738 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
739 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
740
741 typedef _Deque_base<_Tp, _Alloc> _Base;
742 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
743
744 public:
745 typedef _Tp value_type;
746 typedef typename _Tp_alloc_type::pointer pointer;
747 typedef typename _Tp_alloc_type::const_pointer const_pointer;
748 typedef typename _Tp_alloc_type::reference reference;
749 typedef typename _Tp_alloc_type::const_reference const_reference;
750 typedef typename _Base::iterator iterator;
751 typedef typename _Base::const_iterator const_iterator;
752 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
753 typedef std::reverse_iterator<iterator> reverse_iterator;
754 typedef size_t size_type;
755 typedef ptrdiff_t difference_type;
756 typedef _Alloc allocator_type;
757
758 protected:
759 typedef pointer* _Map_pointer;
760
761 static size_t _S_buffer_size()
762 { return __deque_buf_size(sizeof(_Tp)); }
763
764 // Functions controlling memory layout, and nothing else.
765 using _Base::_M_initialize_map;
766 using _Base::_M_create_nodes;
767 using _Base::_M_destroy_nodes;
768 using _Base::_M_allocate_node;
769 using _Base::_M_deallocate_node;
770 using _Base::_M_allocate_map;
771 using _Base::_M_deallocate_map;
772 using _Base::_M_get_Tp_allocator;
773
774 /**
775 * A total of four data members accumulated down the hierarchy.
776 * May be accessed via _M_impl.*
777 */
778 using _Base::_M_impl;
779
780 public:
781 // [23.2.1.1] construct/copy/destroy
782 // (assign() and get_allocator() are also listed in this section)
783 /**
784 * @brief Default constructor creates no elements.
785 */
786 deque()
787 : _Base() { }
788
789 /**
790 * @brief Creates a %deque with no elements.
791 * @param __a An allocator object.
792 */
793 explicit
794 deque(const allocator_type& __a)
795 : _Base(__a, 0) { }
796
797 #if __cplusplus >= 201103L
798 /**
799 * @brief Creates a %deque with default constructed elements.
800 * @param __n The number of elements to initially create.
801 *
802 * This constructor fills the %deque with @a n default
803 * constructed elements.
804 */
805 explicit
806 deque(size_type __n)
807 : _Base(__n)
808 { _M_default_initialize(); }
809
810 /**
811 * @brief Creates a %deque with copies of an exemplar element.
812 * @param __n The number of elements to initially create.
813 * @param __value An element to copy.
814 * @param __a An allocator.
815 *
816 * This constructor fills the %deque with @a __n copies of @a __value.
817 */
818 deque(size_type __n, const value_type& __value,
819 const allocator_type& __a = allocator_type())
820 : _Base(__a, __n)
821 { _M_fill_initialize(__value); }
822 #else
823 /**
824 * @brief Creates a %deque with copies of an exemplar element.
825 * @param __n The number of elements to initially create.
826 * @param __value An element to copy.
827 * @param __a An allocator.
828 *
829 * This constructor fills the %deque with @a __n copies of @a __value.
830 */
831 explicit
832 deque(size_type __n, const value_type& __value = value_type(),
833 const allocator_type& __a = allocator_type())
834 : _Base(__a, __n)
835 { _M_fill_initialize(__value); }
836 #endif
837
838 /**
839 * @brief %Deque copy constructor.
840 * @param __x A %deque of identical element and allocator types.
841 *
842 * The newly-created %deque uses a copy of the allocation object used
843 * by @a __x.
844 */
845 deque(const deque& __x)
846 : _Base(__x._M_get_Tp_allocator(), __x.size())
847 { std::__uninitialized_copy_a(__x.begin(), __x.end(),
848 this->_M_impl._M_start,
849 _M_get_Tp_allocator()); }
850
851 #if __cplusplus >= 201103L
852 /**
853 * @brief %Deque move constructor.
854 * @param __x A %deque of identical element and allocator types.
855 *
856 * The newly-created %deque contains the exact contents of @a __x.
857 * The contents of @a __x are a valid, but unspecified %deque.
858 */
859 deque(deque&& __x)
860 : _Base(std::move(__x)) { }
861
862 /**
863 * @brief Builds a %deque from an initializer list.
864 * @param __l An initializer_list.
865 * @param __a An allocator object.
866 *
867 * Create a %deque consisting of copies of the elements in the
868 * initializer_list @a __l.
869 *
870 * This will call the element type's copy constructor N times
871 * (where N is __l.size()) and do no memory reallocation.
872 */
873 deque(initializer_list<value_type> __l,
874 const allocator_type& __a = allocator_type())
875 : _Base(__a)
876 {
877 _M_range_initialize(__l.begin(), __l.end(),
878 random_access_iterator_tag());
879 }
880 #endif
881
882 /**
883 * @brief Builds a %deque from a range.
884 * @param __first An input iterator.
885 * @param __last An input iterator.
886 * @param __a An allocator object.
887 *
888 * Create a %deque consisting of copies of the elements from [__first,
889 * __last).
890 *
891 * If the iterators are forward, bidirectional, or random-access, then
892 * this will call the elements' copy constructor N times (where N is
893 * distance(__first,__last)) and do no memory reallocation. But if only
894 * input iterators are used, then this will do at most 2N calls to the
895 * copy constructor, and logN memory reallocations.
896 */
897 #if __cplusplus >= 201103L
898 template<typename _InputIterator,
899 typename = std::_RequireInputIter<_InputIterator>>
900 deque(_InputIterator __first, _InputIterator __last,
901 const allocator_type& __a = allocator_type())
902 : _Base(__a)
903 { _M_initialize_dispatch(__first, __last, __false_type()); }
904 #else
905 template<typename _InputIterator>
906 deque(_InputIterator __first, _InputIterator __last,
907 const allocator_type& __a = allocator_type())
908 : _Base(__a)
909 {
910 // Check whether it's an integral type. If so, it's not an iterator.
911 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
912 _M_initialize_dispatch(__first, __last, _Integral());
913 }
914 #endif
915
916 /**
917 * The dtor only erases the elements, and note that if the elements
918 * themselves are pointers, the pointed-to memory is not touched in any
919 * way. Managing the pointer is the user's responsibility.
920 */
921 ~deque() _GLIBCXX_NOEXCEPT
922 { _M_destroy_data(begin(), end(), _M_get_Tp_allocator()); }
923
924 /**
925 * @brief %Deque assignment operator.
926 * @param __x A %deque of identical element and allocator types.
927 *
928 * All the elements of @a x are copied, but unlike the copy constructor,
929 * the allocator object is not copied.
930 */
931 deque&
932 operator=(const deque& __x);
933
934 #if __cplusplus >= 201103L
935 /**
936 * @brief %Deque move assignment operator.
937 * @param __x A %deque of identical element and allocator types.
938 *
939 * The contents of @a __x are moved into this deque (without copying).
940 * @a __x is a valid, but unspecified %deque.
941 */
942 deque&
943 operator=(deque&& __x)
944 {
945 // NB: DR 1204.
946 // NB: DR 675.
947 this->clear();
948 this->swap(__x);
949 return *this;
950 }
951
952 /**
953 * @brief Assigns an initializer list to a %deque.
954 * @param __l An initializer_list.
955 *
956 * This function fills a %deque with copies of the elements in the
957 * initializer_list @a __l.
958 *
959 * Note that the assignment completely changes the %deque and that the
960 * resulting %deque's size is the same as the number of elements
961 * assigned. Old data may be lost.
962 */
963 deque&
964 operator=(initializer_list<value_type> __l)
965 {
966 this->assign(__l.begin(), __l.end());
967 return *this;
968 }
969 #endif
970
971 /**
972 * @brief Assigns a given value to a %deque.
973 * @param __n Number of elements to be assigned.
974 * @param __val Value to be assigned.
975 *
976 * This function fills a %deque with @a n copies of the given
977 * value. Note that the assignment completely changes the
978 * %deque and that the resulting %deque's size is the same as
979 * the number of elements assigned. Old data may be lost.
980 */
981 void
982 assign(size_type __n, const value_type& __val)
983 { _M_fill_assign(__n, __val); }
984
985 /**
986 * @brief Assigns a range to a %deque.
987 * @param __first An input iterator.
988 * @param __last An input iterator.
989 *
990 * This function fills a %deque with copies of the elements in the
991 * range [__first,__last).
992 *
993 * Note that the assignment completely changes the %deque and that the
994 * resulting %deque's size is the same as the number of elements
995 * assigned. Old data may be lost.
996 */
997 #if __cplusplus >= 201103L
998 template<typename _InputIterator,
999 typename = std::_RequireInputIter<_InputIterator>>
1000 void
1001 assign(_InputIterator __first, _InputIterator __last)
1002 { _M_assign_dispatch(__first, __last, __false_type()); }
1003 #else
1004 template<typename _InputIterator>
1005 void
1006 assign(_InputIterator __first, _InputIterator __last)
1007 {
1008 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1009 _M_assign_dispatch(__first, __last, _Integral());
1010 }
1011 #endif
1012
1013 #if __cplusplus >= 201103L
1014 /**
1015 * @brief Assigns an initializer list to a %deque.
1016 * @param __l An initializer_list.
1017 *
1018 * This function fills a %deque with copies of the elements in the
1019 * initializer_list @a __l.
1020 *
1021 * Note that the assignment completely changes the %deque and that the
1022 * resulting %deque's size is the same as the number of elements
1023 * assigned. Old data may be lost.
1024 */
1025 void
1026 assign(initializer_list<value_type> __l)
1027 { this->assign(__l.begin(), __l.end()); }
1028 #endif
1029
1030 /// Get a copy of the memory allocation object.
1031 allocator_type
1032 get_allocator() const _GLIBCXX_NOEXCEPT
1033 { return _Base::get_allocator(); }
1034
1035 // iterators
1036 /**
1037 * Returns a read/write iterator that points to the first element in the
1038 * %deque. Iteration is done in ordinary element order.
1039 */
1040 iterator
1041 begin() _GLIBCXX_NOEXCEPT
1042 { return this->_M_impl._M_start; }
1043
1044 /**
1045 * Returns a read-only (constant) iterator that points to the first
1046 * element in the %deque. Iteration is done in ordinary element order.
1047 */
1048 const_iterator
1049 begin() const _GLIBCXX_NOEXCEPT
1050 { return this->_M_impl._M_start; }
1051
1052 /**
1053 * Returns a read/write iterator that points one past the last
1054 * element in the %deque. Iteration is done in ordinary
1055 * element order.
1056 */
1057 iterator
1058 end() _GLIBCXX_NOEXCEPT
1059 { return this->_M_impl._M_finish; }
1060
1061 /**
1062 * Returns a read-only (constant) iterator that points one past
1063 * the last element in the %deque. Iteration is done in
1064 * ordinary element order.
1065 */
1066 const_iterator
1067 end() const _GLIBCXX_NOEXCEPT
1068 { return this->_M_impl._M_finish; }
1069
1070 /**
1071 * Returns a read/write reverse iterator that points to the
1072 * last element in the %deque. Iteration is done in reverse
1073 * element order.
1074 */
1075 reverse_iterator
1076 rbegin() _GLIBCXX_NOEXCEPT
1077 { return reverse_iterator(this->_M_impl._M_finish); }
1078
1079 /**
1080 * Returns a read-only (constant) reverse iterator that points
1081 * to the last element in the %deque. Iteration is done in
1082 * reverse element order.
1083 */
1084 const_reverse_iterator
1085 rbegin() const _GLIBCXX_NOEXCEPT
1086 { return const_reverse_iterator(this->_M_impl._M_finish); }
1087
1088 /**
1089 * Returns a read/write reverse iterator that points to one
1090 * before the first element in the %deque. Iteration is done
1091 * in reverse element order.
1092 */
1093 reverse_iterator
1094 rend() _GLIBCXX_NOEXCEPT
1095 { return reverse_iterator(this->_M_impl._M_start); }
1096
1097 /**
1098 * Returns a read-only (constant) reverse iterator that points
1099 * to one before the first element in the %deque. Iteration is
1100 * done in reverse element order.
1101 */
1102 const_reverse_iterator
1103 rend() const _GLIBCXX_NOEXCEPT
1104 { return const_reverse_iterator(this->_M_impl._M_start); }
1105
1106 #if __cplusplus >= 201103L
1107 /**
1108 * Returns a read-only (constant) iterator that points to the first
1109 * element in the %deque. Iteration is done in ordinary element order.
1110 */
1111 const_iterator
1112 cbegin() const noexcept
1113 { return this->_M_impl._M_start; }
1114
1115 /**
1116 * Returns a read-only (constant) iterator that points one past
1117 * the last element in the %deque. Iteration is done in
1118 * ordinary element order.
1119 */
1120 const_iterator
1121 cend() const noexcept
1122 { return this->_M_impl._M_finish; }
1123
1124 /**
1125 * Returns a read-only (constant) reverse iterator that points
1126 * to the last element in the %deque. Iteration is done in
1127 * reverse element order.
1128 */
1129 const_reverse_iterator
1130 crbegin() const noexcept
1131 { return const_reverse_iterator(this->_M_impl._M_finish); }
1132
1133 /**
1134 * Returns a read-only (constant) reverse iterator that points
1135 * to one before the first element in the %deque. Iteration is
1136 * done in reverse element order.
1137 */
1138 const_reverse_iterator
1139 crend() const noexcept
1140 { return const_reverse_iterator(this->_M_impl._M_start); }
1141 #endif
1142
1143 // [23.2.1.2] capacity
1144 /** Returns the number of elements in the %deque. */
1145 size_type
1146 size() const _GLIBCXX_NOEXCEPT
1147 { return this->_M_impl._M_finish - this->_M_impl._M_start; }
1148
1149 /** Returns the size() of the largest possible %deque. */
1150 size_type
1151 max_size() const _GLIBCXX_NOEXCEPT
1152 { return _M_get_Tp_allocator().max_size(); }
1153
1154 #if __cplusplus >= 201103L
1155 /**
1156 * @brief Resizes the %deque to the specified number of elements.
1157 * @param __new_size Number of elements the %deque should contain.
1158 *
1159 * This function will %resize the %deque to the specified
1160 * number of elements. If the number is smaller than the
1161 * %deque's current size the %deque is truncated, otherwise
1162 * default constructed elements are appended.
1163 */
1164 void
1165 resize(size_type __new_size)
1166 {
1167 const size_type __len = size();
1168 if (__new_size > __len)
1169 _M_default_append(__new_size - __len);
1170 else if (__new_size < __len)
1171 _M_erase_at_end(this->_M_impl._M_start
1172 + difference_type(__new_size));
1173 }
1174
1175 /**
1176 * @brief Resizes the %deque to the specified number of elements.
1177 * @param __new_size Number of elements the %deque should contain.
1178 * @param __x Data with which new elements should be populated.
1179 *
1180 * This function will %resize the %deque to the specified
1181 * number of elements. If the number is smaller than the
1182 * %deque's current size the %deque is truncated, otherwise the
1183 * %deque is extended and new elements are populated with given
1184 * data.
1185 */
1186 void
1187 resize(size_type __new_size, const value_type& __x)
1188 {
1189 const size_type __len = size();
1190 if (__new_size > __len)
1191 insert(this->_M_impl._M_finish, __new_size - __len, __x);
1192 else if (__new_size < __len)
1193 _M_erase_at_end(this->_M_impl._M_start
1194 + difference_type(__new_size));
1195 }
1196 #else
1197 /**
1198 * @brief Resizes the %deque to the specified number of elements.
1199 * @param __new_size Number of elements the %deque should contain.
1200 * @param __x Data with which new elements should be populated.
1201 *
1202 * This function will %resize the %deque to the specified
1203 * number of elements. If the number is smaller than the
1204 * %deque's current size the %deque is truncated, otherwise the
1205 * %deque is extended and new elements are populated with given
1206 * data.
1207 */
1208 void
1209 resize(size_type __new_size, value_type __x = value_type())
1210 {
1211 const size_type __len = size();
1212 if (__new_size > __len)
1213 insert(this->_M_impl._M_finish, __new_size - __len, __x);
1214 else if (__new_size < __len)
1215 _M_erase_at_end(this->_M_impl._M_start
1216 + difference_type(__new_size));
1217 }
1218 #endif
1219
1220 #if __cplusplus >= 201103L
1221 /** A non-binding request to reduce memory use. */
1222 void
1223 shrink_to_fit()
1224 { _M_shrink_to_fit(); }
1225 #endif
1226
1227 /**
1228 * Returns true if the %deque is empty. (Thus begin() would
1229 * equal end().)
1230 */
1231 bool
1232 empty() const _GLIBCXX_NOEXCEPT
1233 { return this->_M_impl._M_finish == this->_M_impl._M_start; }
1234
1235 // element access
1236 /**
1237 * @brief Subscript access to the data contained in the %deque.
1238 * @param __n The index of the element for which data should be
1239 * accessed.
1240 * @return Read/write reference to data.
1241 *
1242 * This operator allows for easy, array-style, data access.
1243 * Note that data access with this operator is unchecked and
1244 * out_of_range lookups are not defined. (For checked lookups
1245 * see at().)
1246 */
1247 reference
1248 operator[](size_type __n)
1249 { return this->_M_impl._M_start[difference_type(__n)]; }
1250
1251 /**
1252 * @brief Subscript access to the data contained in the %deque.
1253 * @param __n The index of the element for which data should be
1254 * accessed.
1255 * @return Read-only (constant) reference to data.
1256 *
1257 * This operator allows for easy, array-style, data access.
1258 * Note that data access with this operator is unchecked and
1259 * out_of_range lookups are not defined. (For checked lookups
1260 * see at().)
1261 */
1262 const_reference
1263 operator[](size_type __n) const
1264 { return this->_M_impl._M_start[difference_type(__n)]; }
1265
1266 protected:
1267 /// Safety check used only from at().
1268 void
1269 _M_range_check(size_type __n) const
1270 {
1271 if (__n >= this->size())
1272 __throw_out_of_range(__N("deque::_M_range_check"));
1273 }
1274
1275 public:
1276 /**
1277 * @brief Provides access to the data contained in the %deque.
1278 * @param __n The index of the element for which data should be
1279 * accessed.
1280 * @return Read/write reference to data.
1281 * @throw std::out_of_range If @a __n is an invalid index.
1282 *
1283 * This function provides for safer data access. The parameter
1284 * is first checked that it is in the range of the deque. The
1285 * function throws out_of_range if the check fails.
1286 */
1287 reference
1288 at(size_type __n)
1289 {
1290 _M_range_check(__n);
1291 return (*this)[__n];
1292 }
1293
1294 /**
1295 * @brief Provides access to the data contained in the %deque.
1296 * @param __n The index of the element for which data should be
1297 * accessed.
1298 * @return Read-only (constant) reference to data.
1299 * @throw std::out_of_range If @a __n is an invalid index.
1300 *
1301 * This function provides for safer data access. The parameter is first
1302 * checked that it is in the range of the deque. The function throws
1303 * out_of_range if the check fails.
1304 */
1305 const_reference
1306 at(size_type __n) const
1307 {
1308 _M_range_check(__n);
1309 return (*this)[__n];
1310 }
1311
1312 /**
1313 * Returns a read/write reference to the data at the first
1314 * element of the %deque.
1315 */
1316 reference
1317 front()
1318 { return *begin(); }
1319
1320 /**
1321 * Returns a read-only (constant) reference to the data at the first
1322 * element of the %deque.
1323 */
1324 const_reference
1325 front() const
1326 { return *begin(); }
1327
1328 /**
1329 * Returns a read/write reference to the data at the last element of the
1330 * %deque.
1331 */
1332 reference
1333 back()
1334 {
1335 iterator __tmp = end();
1336 --__tmp;
1337 return *__tmp;
1338 }
1339
1340 /**
1341 * Returns a read-only (constant) reference to the data at the last
1342 * element of the %deque.
1343 */
1344 const_reference
1345 back() const
1346 {
1347 const_iterator __tmp = end();
1348 --__tmp;
1349 return *__tmp;
1350 }
1351
1352 // [23.2.1.2] modifiers
1353 /**
1354 * @brief Add data to the front of the %deque.
1355 * @param __x Data to be added.
1356 *
1357 * This is a typical stack operation. The function creates an
1358 * element at the front of the %deque and assigns the given
1359 * data to it. Due to the nature of a %deque this operation
1360 * can be done in constant time.
1361 */
1362 void
1363 push_front(const value_type& __x)
1364 {
1365 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1366 {
1367 this->_M_impl.construct(this->_M_impl._M_start._M_cur - 1, __x);
1368 --this->_M_impl._M_start._M_cur;
1369 }
1370 else
1371 _M_push_front_aux(__x);
1372 }
1373
1374 #if __cplusplus >= 201103L
1375 void
1376 push_front(value_type&& __x)
1377 { emplace_front(std::move(__x)); }
1378
1379 template<typename... _Args>
1380 void
1381 emplace_front(_Args&&... __args);
1382 #endif
1383
1384 /**
1385 * @brief Add data to the end of the %deque.
1386 * @param __x Data to be added.
1387 *
1388 * This is a typical stack operation. The function creates an
1389 * element at the end of the %deque and assigns the given data
1390 * to it. Due to the nature of a %deque this operation can be
1391 * done in constant time.
1392 */
1393 void
1394 push_back(const value_type& __x)
1395 {
1396 if (this->_M_impl._M_finish._M_cur
1397 != this->_M_impl._M_finish._M_last - 1)
1398 {
1399 this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __x);
1400 ++this->_M_impl._M_finish._M_cur;
1401 }
1402 else
1403 _M_push_back_aux(__x);
1404 }
1405
1406 #if __cplusplus >= 201103L
1407 void
1408 push_back(value_type&& __x)
1409 { emplace_back(std::move(__x)); }
1410
1411 template<typename... _Args>
1412 void
1413 emplace_back(_Args&&... __args);
1414 #endif
1415
1416 /**
1417 * @brief Removes first element.
1418 *
1419 * This is a typical stack operation. It shrinks the %deque by one.
1420 *
1421 * Note that no data is returned, and if the first element's data is
1422 * needed, it should be retrieved before pop_front() is called.
1423 */
1424 void
1425 pop_front()
1426 {
1427 if (this->_M_impl._M_start._M_cur
1428 != this->_M_impl._M_start._M_last - 1)
1429 {
1430 this->_M_impl.destroy(this->_M_impl._M_start._M_cur);
1431 ++this->_M_impl._M_start._M_cur;
1432 }
1433 else
1434 _M_pop_front_aux();
1435 }
1436
1437 /**
1438 * @brief Removes last element.
1439 *
1440 * This is a typical stack operation. It shrinks the %deque by one.
1441 *
1442 * Note that no data is returned, and if the last element's data is
1443 * needed, it should be retrieved before pop_back() is called.
1444 */
1445 void
1446 pop_back()
1447 {
1448 if (this->_M_impl._M_finish._M_cur
1449 != this->_M_impl._M_finish._M_first)
1450 {
1451 --this->_M_impl._M_finish._M_cur;
1452 this->_M_impl.destroy(this->_M_impl._M_finish._M_cur);
1453 }
1454 else
1455 _M_pop_back_aux();
1456 }
1457
1458 #if __cplusplus >= 201103L
1459 /**
1460 * @brief Inserts an object in %deque before specified iterator.
1461 * @param __position An iterator into the %deque.
1462 * @param __args Arguments.
1463 * @return An iterator that points to the inserted data.
1464 *
1465 * This function will insert an object of type T constructed
1466 * with T(std::forward<Args>(args)...) before the specified location.
1467 */
1468 template<typename... _Args>
1469 iterator
1470 emplace(iterator __position, _Args&&... __args);
1471 #endif
1472
1473 /**
1474 * @brief Inserts given value into %deque before specified iterator.
1475 * @param __position An iterator into the %deque.
1476 * @param __x Data to be inserted.
1477 * @return An iterator that points to the inserted data.
1478 *
1479 * This function will insert a copy of the given value before the
1480 * specified location.
1481 */
1482 iterator
1483 insert(iterator __position, const value_type& __x);
1484
1485 #if __cplusplus >= 201103L
1486 /**
1487 * @brief Inserts given rvalue into %deque before specified iterator.
1488 * @param __position An iterator into the %deque.
1489 * @param __x Data to be inserted.
1490 * @return An iterator that points to the inserted data.
1491 *
1492 * This function will insert a copy of the given rvalue before the
1493 * specified location.
1494 */
1495 iterator
1496 insert(iterator __position, value_type&& __x)
1497 { return emplace(__position, std::move(__x)); }
1498
1499 /**
1500 * @brief Inserts an initializer list into the %deque.
1501 * @param __p An iterator into the %deque.
1502 * @param __l An initializer_list.
1503 *
1504 * This function will insert copies of the data in the
1505 * initializer_list @a __l into the %deque before the location
1506 * specified by @a __p. This is known as <em>list insert</em>.
1507 */
1508 void
1509 insert(iterator __p, initializer_list<value_type> __l)
1510 { this->insert(__p, __l.begin(), __l.end()); }
1511 #endif
1512
1513 /**
1514 * @brief Inserts a number of copies of given data into the %deque.
1515 * @param __position An iterator into the %deque.
1516 * @param __n Number of elements to be inserted.
1517 * @param __x Data to be inserted.
1518 *
1519 * This function will insert a specified number of copies of the given
1520 * data before the location specified by @a __position.
1521 */
1522 void
1523 insert(iterator __position, size_type __n, const value_type& __x)
1524 { _M_fill_insert(__position, __n, __x); }
1525
1526 /**
1527 * @brief Inserts a range into the %deque.
1528 * @param __position An iterator into the %deque.
1529 * @param __first An input iterator.
1530 * @param __last An input iterator.
1531 *
1532 * This function will insert copies of the data in the range
1533 * [__first,__last) into the %deque before the location specified
1534 * by @a __position. This is known as <em>range insert</em>.
1535 */
1536 #if __cplusplus >= 201103L
1537 template<typename _InputIterator,
1538 typename = std::_RequireInputIter<_InputIterator>>
1539 void
1540 insert(iterator __position, _InputIterator __first,
1541 _InputIterator __last)
1542 { _M_insert_dispatch(__position, __first, __last, __false_type()); }
1543 #else
1544 template<typename _InputIterator>
1545 void
1546 insert(iterator __position, _InputIterator __first,
1547 _InputIterator __last)
1548 {
1549 // Check whether it's an integral type. If so, it's not an iterator.
1550 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1551 _M_insert_dispatch(__position, __first, __last, _Integral());
1552 }
1553 #endif
1554
1555 /**
1556 * @brief Remove element at given position.
1557 * @param __position Iterator pointing to element to be erased.
1558 * @return An iterator pointing to the next element (or end()).
1559 *
1560 * This function will erase the element at the given position and thus
1561 * shorten the %deque by one.
1562 *
1563 * The user is cautioned that
1564 * this function only erases the element, and that if the element is
1565 * itself a pointer, the pointed-to memory is not touched in any way.
1566 * Managing the pointer is the user's responsibility.
1567 */
1568 iterator
1569 #if __cplusplus >= 201103L
1570 erase(const_iterator __position)
1571 { return _M_erase(__position._M_const_cast()); }
1572 #else
1573 erase(iterator __position)
1574 { return _M_erase(__position); }
1575 #endif
1576
1577 /**
1578 * @brief Remove a range of elements.
1579 * @param __first Iterator pointing to the first element to be erased.
1580 * @param __last Iterator pointing to one past the last element to be
1581 * erased.
1582 * @return An iterator pointing to the element pointed to by @a last
1583 * prior to erasing (or end()).
1584 *
1585 * This function will erase the elements in the range
1586 * [__first,__last) and shorten the %deque accordingly.
1587 *
1588 * The user is cautioned that
1589 * this function only erases the elements, and that if the elements
1590 * themselves are pointers, the pointed-to memory is not touched in any
1591 * way. Managing the pointer is the user's responsibility.
1592 */
1593 iterator
1594 #if __cplusplus >= 201103L
1595 erase(const_iterator __first, const_iterator __last)
1596 { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1597 #else
1598 erase(iterator __first, iterator __last)
1599 { return _M_erase(__first, __last); }
1600 #endif
1601
1602 /**
1603 * @brief Swaps data with another %deque.
1604 * @param __x A %deque of the same element and allocator types.
1605 *
1606 * This exchanges the elements between two deques in constant time.
1607 * (Four pointers, so it should be quite fast.)
1608 * Note that the global std::swap() function is specialized such that
1609 * std::swap(d1,d2) will feed to this function.
1610 */
1611 void
1612 swap(deque& __x)
1613 {
1614 std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
1615 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
1616 std::swap(this->_M_impl._M_map, __x._M_impl._M_map);
1617 std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size);
1618
1619 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1620 // 431. Swapping containers with unequal allocators.
1621 std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(),
1622 __x._M_get_Tp_allocator());
1623 }
1624
1625 /**
1626 * Erases all the elements. Note that this function only erases the
1627 * elements, and that if the elements themselves are pointers, the
1628 * pointed-to memory is not touched in any way. Managing the pointer is
1629 * the user's responsibility.
1630 */
1631 void
1632 clear() _GLIBCXX_NOEXCEPT
1633 { _M_erase_at_end(begin()); }
1634
1635 protected:
1636 // Internal constructor functions follow.
1637
1638 // called by the range constructor to implement [23.1.1]/9
1639
1640 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1641 // 438. Ambiguity in the "do the right thing" clause
1642 template<typename _Integer>
1643 void
1644 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1645 {
1646 _M_initialize_map(static_cast<size_type>(__n));
1647 _M_fill_initialize(__x);
1648 }
1649
1650 // called by the range constructor to implement [23.1.1]/9
1651 template<typename _InputIterator>
1652 void
1653 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1654 __false_type)
1655 {
1656 typedef typename std::iterator_traits<_InputIterator>::
1657 iterator_category _IterCategory;
1658 _M_range_initialize(__first, __last, _IterCategory());
1659 }
1660
1661 // called by the second initialize_dispatch above
1662 //@{
1663 /**
1664 * @brief Fills the deque with whatever is in [first,last).
1665 * @param __first An input iterator.
1666 * @param __last An input iterator.
1667 * @return Nothing.
1668 *
1669 * If the iterators are actually forward iterators (or better), then the
1670 * memory layout can be done all at once. Else we move forward using
1671 * push_back on each value from the iterator.
1672 */
1673 template<typename _InputIterator>
1674 void
1675 _M_range_initialize(_InputIterator __first, _InputIterator __last,
1676 std::input_iterator_tag);
1677
1678 // called by the second initialize_dispatch above
1679 template<typename _ForwardIterator>
1680 void
1681 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1682 std::forward_iterator_tag);
1683 //@}
1684
1685 /**
1686 * @brief Fills the %deque with copies of value.
1687 * @param __value Initial value.
1688 * @return Nothing.
1689 * @pre _M_start and _M_finish have already been initialized,
1690 * but none of the %deque's elements have yet been constructed.
1691 *
1692 * This function is called only when the user provides an explicit size
1693 * (with or without an explicit exemplar value).
1694 */
1695 void
1696 _M_fill_initialize(const value_type& __value);
1697
1698 #if __cplusplus >= 201103L
1699 // called by deque(n).
1700 void
1701 _M_default_initialize();
1702 #endif
1703
1704 // Internal assign functions follow. The *_aux functions do the actual
1705 // assignment work for the range versions.
1706
1707 // called by the range assign to implement [23.1.1]/9
1708
1709 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1710 // 438. Ambiguity in the "do the right thing" clause
1711 template<typename _Integer>
1712 void
1713 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1714 { _M_fill_assign(__n, __val); }
1715
1716 // called by the range assign to implement [23.1.1]/9
1717 template<typename _InputIterator>
1718 void
1719 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1720 __false_type)
1721 {
1722 typedef typename std::iterator_traits<_InputIterator>::
1723 iterator_category _IterCategory;
1724 _M_assign_aux(__first, __last, _IterCategory());
1725 }
1726
1727 // called by the second assign_dispatch above
1728 template<typename _InputIterator>
1729 void
1730 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1731 std::input_iterator_tag);
1732
1733 // called by the second assign_dispatch above
1734 template<typename _ForwardIterator>
1735 void
1736 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1737 std::forward_iterator_tag)
1738 {
1739 const size_type __len = std::distance(__first, __last);
1740 if (__len > size())
1741 {
1742 _ForwardIterator __mid = __first;
1743 std::advance(__mid, size());
1744 std::copy(__first, __mid, begin());
1745 insert(end(), __mid, __last);
1746 }
1747 else
1748 _M_erase_at_end(std::copy(__first, __last, begin()));
1749 }
1750
1751 // Called by assign(n,t), and the range assign when it turns out
1752 // to be the same thing.
1753 void
1754 _M_fill_assign(size_type __n, const value_type& __val)
1755 {
1756 if (__n > size())
1757 {
1758 std::fill(begin(), end(), __val);
1759 insert(end(), __n - size(), __val);
1760 }
1761 else
1762 {
1763 _M_erase_at_end(begin() + difference_type(__n));
1764 std::fill(begin(), end(), __val);
1765 }
1766 }
1767
1768 //@{
1769 /// Helper functions for push_* and pop_*.
1770 #if __cplusplus < 201103L
1771 void _M_push_back_aux(const value_type&);
1772
1773 void _M_push_front_aux(const value_type&);
1774 #else
1775 template<typename... _Args>
1776 void _M_push_back_aux(_Args&&... __args);
1777
1778 template<typename... _Args>
1779 void _M_push_front_aux(_Args&&... __args);
1780 #endif
1781
1782 void _M_pop_back_aux();
1783
1784 void _M_pop_front_aux();
1785 //@}
1786
1787 // Internal insert functions follow. The *_aux functions do the actual
1788 // insertion work when all shortcuts fail.
1789
1790 // called by the range insert to implement [23.1.1]/9
1791
1792 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1793 // 438. Ambiguity in the "do the right thing" clause
1794 template<typename _Integer>
1795 void
1796 _M_insert_dispatch(iterator __pos,
1797 _Integer __n, _Integer __x, __true_type)
1798 { _M_fill_insert(__pos, __n, __x); }
1799
1800 // called by the range insert to implement [23.1.1]/9
1801 template<typename _InputIterator>
1802 void
1803 _M_insert_dispatch(iterator __pos,
1804 _InputIterator __first, _InputIterator __last,
1805 __false_type)
1806 {
1807 typedef typename std::iterator_traits<_InputIterator>::
1808 iterator_category _IterCategory;
1809 _M_range_insert_aux(__pos, __first, __last, _IterCategory());
1810 }
1811
1812 // called by the second insert_dispatch above
1813 template<typename _InputIterator>
1814 void
1815 _M_range_insert_aux(iterator __pos, _InputIterator __first,
1816 _InputIterator __last, std::input_iterator_tag);
1817
1818 // called by the second insert_dispatch above
1819 template<typename _ForwardIterator>
1820 void
1821 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
1822 _ForwardIterator __last, std::forward_iterator_tag);
1823
1824 // Called by insert(p,n,x), and the range insert when it turns out to be
1825 // the same thing. Can use fill functions in optimal situations,
1826 // otherwise passes off to insert_aux(p,n,x).
1827 void
1828 _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
1829
1830 // called by insert(p,x)
1831 #if __cplusplus < 201103L
1832 iterator
1833 _M_insert_aux(iterator __pos, const value_type& __x);
1834 #else
1835 template<typename... _Args>
1836 iterator
1837 _M_insert_aux(iterator __pos, _Args&&... __args);
1838 #endif
1839
1840 // called by insert(p,n,x) via fill_insert
1841 void
1842 _M_insert_aux(iterator __pos, size_type __n, const value_type& __x);
1843
1844 // called by range_insert_aux for forward iterators
1845 template<typename _ForwardIterator>
1846 void
1847 _M_insert_aux(iterator __pos,
1848 _ForwardIterator __first, _ForwardIterator __last,
1849 size_type __n);
1850
1851
1852 // Internal erase functions follow.
1853
1854 void
1855 _M_destroy_data_aux(iterator __first, iterator __last);
1856
1857 // Called by ~deque().
1858 // NB: Doesn't deallocate the nodes.
1859 template<typename _Alloc1>
1860 void
1861 _M_destroy_data(iterator __first, iterator __last, const _Alloc1&)
1862 { _M_destroy_data_aux(__first, __last); }
1863
1864 void
1865 _M_destroy_data(iterator __first, iterator __last,
1866 const std::allocator<_Tp>&)
1867 {
1868 if (!__has_trivial_destructor(value_type))
1869 _M_destroy_data_aux(__first, __last);
1870 }
1871
1872 // Called by erase(q1, q2).
1873 void
1874 _M_erase_at_begin(iterator __pos)
1875 {
1876 _M_destroy_data(begin(), __pos, _M_get_Tp_allocator());
1877 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
1878 this->_M_impl._M_start = __pos;
1879 }
1880
1881 // Called by erase(q1, q2), resize(), clear(), _M_assign_aux,
1882 // _M_fill_assign, operator=.
1883 void
1884 _M_erase_at_end(iterator __pos)
1885 {
1886 _M_destroy_data(__pos, end(), _M_get_Tp_allocator());
1887 _M_destroy_nodes(__pos._M_node + 1,
1888 this->_M_impl._M_finish._M_node + 1);
1889 this->_M_impl._M_finish = __pos;
1890 }
1891
1892 iterator
1893 _M_erase(iterator __pos);
1894
1895 iterator
1896 _M_erase(iterator __first, iterator __last);
1897
1898 #if __cplusplus >= 201103L
1899 // Called by resize(sz).
1900 void
1901 _M_default_append(size_type __n);
1902
1903 bool
1904 _M_shrink_to_fit();
1905 #endif
1906
1907 //@{
1908 /// Memory-handling helpers for the previous internal insert functions.
1909 iterator
1910 _M_reserve_elements_at_front(size_type __n)
1911 {
1912 const size_type __vacancies = this->_M_impl._M_start._M_cur
1913 - this->_M_impl._M_start._M_first;
1914 if (__n > __vacancies)
1915 _M_new_elements_at_front(__n - __vacancies);
1916 return this->_M_impl._M_start - difference_type(__n);
1917 }
1918
1919 iterator
1920 _M_reserve_elements_at_back(size_type __n)
1921 {
1922 const size_type __vacancies = (this->_M_impl._M_finish._M_last
1923 - this->_M_impl._M_finish._M_cur) - 1;
1924 if (__n > __vacancies)
1925 _M_new_elements_at_back(__n - __vacancies);
1926 return this->_M_impl._M_finish + difference_type(__n);
1927 }
1928
1929 void
1930 _M_new_elements_at_front(size_type __new_elements);
1931
1932 void
1933 _M_new_elements_at_back(size_type __new_elements);
1934 //@}
1935
1936
1937 //@{
1938 /**
1939 * @brief Memory-handling helpers for the major %map.
1940 *
1941 * Makes sure the _M_map has space for new nodes. Does not
1942 * actually add the nodes. Can invalidate _M_map pointers.
1943 * (And consequently, %deque iterators.)
1944 */
1945 void
1946 _M_reserve_map_at_back(size_type __nodes_to_add = 1)
1947 {
1948 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
1949 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
1950 _M_reallocate_map(__nodes_to_add, false);
1951 }
1952
1953 void
1954 _M_reserve_map_at_front(size_type __nodes_to_add = 1)
1955 {
1956 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
1957 - this->_M_impl._M_map))
1958 _M_reallocate_map(__nodes_to_add, true);
1959 }
1960
1961 void
1962 _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
1963 //@}
1964 };
1965
1966
1967 /**
1968 * @brief Deque equality comparison.
1969 * @param __x A %deque.
1970 * @param __y A %deque of the same type as @a __x.
1971 * @return True iff the size and elements of the deques are equal.
1972 *
1973 * This is an equivalence relation. It is linear in the size of the
1974 * deques. Deques are considered equivalent if their sizes are equal,
1975 * and if corresponding elements compare equal.
1976 */
1977 template<typename _Tp, typename _Alloc>
1978 inline bool
1979 operator==(const deque<_Tp, _Alloc>& __x,
1980 const deque<_Tp, _Alloc>& __y)
1981 { return __x.size() == __y.size()
1982 && std::equal(__x.begin(), __x.end(), __y.begin()); }
1983
1984 /**
1985 * @brief Deque ordering relation.
1986 * @param __x A %deque.
1987 * @param __y A %deque of the same type as @a __x.
1988 * @return True iff @a x is lexicographically less than @a __y.
1989 *
1990 * This is a total ordering relation. It is linear in the size of the
1991 * deques. The elements must be comparable with @c <.
1992 *
1993 * See std::lexicographical_compare() for how the determination is made.
1994 */
1995 template<typename _Tp, typename _Alloc>
1996 inline bool
1997 operator<(const deque<_Tp, _Alloc>& __x,
1998 const deque<_Tp, _Alloc>& __y)
1999 { return std::lexicographical_compare(__x.begin(), __x.end(),
2000 __y.begin(), __y.end()); }
2001
2002 /// Based on operator==
2003 template<typename _Tp, typename _Alloc>
2004 inline bool
2005 operator!=(const deque<_Tp, _Alloc>& __x,
2006 const deque<_Tp, _Alloc>& __y)
2007 { return !(__x == __y); }
2008
2009 /// Based on operator<
2010 template<typename _Tp, typename _Alloc>
2011 inline bool
2012 operator>(const deque<_Tp, _Alloc>& __x,
2013 const deque<_Tp, _Alloc>& __y)
2014 { return __y < __x; }
2015
2016 /// Based on operator<
2017 template<typename _Tp, typename _Alloc>
2018 inline bool
2019 operator<=(const deque<_Tp, _Alloc>& __x,
2020 const deque<_Tp, _Alloc>& __y)
2021 { return !(__y < __x); }
2022
2023 /// Based on operator<
2024 template<typename _Tp, typename _Alloc>
2025 inline bool
2026 operator>=(const deque<_Tp, _Alloc>& __x,
2027 const deque<_Tp, _Alloc>& __y)
2028 { return !(__x < __y); }
2029
2030 /// See std::deque::swap().
2031 template<typename _Tp, typename _Alloc>
2032 inline void
2033 swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
2034 { __x.swap(__y); }
2035
2036 #undef _GLIBCXX_DEQUE_BUF_SIZE
2037
2038 _GLIBCXX_END_NAMESPACE_CONTAINER
2039 } // namespace std
2040
2041 #endif /* _STL_DEQUE_H */