1 // Deque implementation (out of line) -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
34 * Hewlett-Packard Company
36 * Permission to use, copy, modify, distribute and sell this software
37 * and its documentation for any purpose is hereby granted without fee,
38 * provided that the above copyright notice appear in all copies and
39 * that both that copyright notice and this permission notice appear
40 * in supporting documentation. Hewlett-Packard Company makes no
41 * representations about the suitability of this software for any
42 * purpose. It is provided "as is" without express or implied warranty.
46 * Silicon Graphics Computer Systems, Inc.
48 * Permission to use, copy, modify, distribute and sell this software
49 * and its documentation for any purpose is hereby granted without fee,
50 * provided that the above copyright notice appear in all copies and
51 * that both that copyright notice and this permission notice appear
52 * in supporting documentation. Silicon Graphics makes no
53 * representations about the suitability of this software for any
54 * purpose. It is provided "as is" without express or implied warranty.
58 * This is an internal header file, included by other library headers.
59 * You should not attempt to use it directly.
65 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
67 template <typename _Tp, typename _Alloc>
70 operator=(const deque& __x)
72 const size_type __len = size();
75 if (__len >= __x.size())
76 _M_erase_at_end(std::copy(__x.begin(), __x.end(),
77 this->_M_impl._M_start));
80 const_iterator __mid = __x.begin() + difference_type(__len);
81 std::copy(__x.begin(), __mid, this->_M_impl._M_start);
82 insert(this->_M_impl._M_finish, __mid, __x.end());
88 #ifdef __GXX_EXPERIMENTAL_CXX0X__
89 template<typename _Tp, typename _Alloc>
90 template<typename... _Args>
93 emplace_front(_Args&&... __args)
95 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
97 this->_M_impl.construct(this->_M_impl._M_start._M_cur - 1,
98 std::forward<_Args>(__args)...);
99 --this->_M_impl._M_start._M_cur;
102 _M_push_front_aux(std::forward<_Args>(__args)...);
105 template<typename _Tp, typename _Alloc>
106 template<typename... _Args>
109 emplace_back(_Args&&... __args)
111 if (this->_M_impl._M_finish._M_cur
112 != this->_M_impl._M_finish._M_last - 1)
114 this->_M_impl.construct(this->_M_impl._M_finish._M_cur,
115 std::forward<_Args>(__args)...);
116 ++this->_M_impl._M_finish._M_cur;
119 _M_push_back_aux(std::forward<_Args>(__args)...);
123 template <typename _Tp, typename _Alloc>
124 typename deque<_Tp, _Alloc>::iterator
126 insert(iterator __position, const value_type& __x)
128 if (__position._M_cur == this->_M_impl._M_start._M_cur)
131 return this->_M_impl._M_start;
133 else if (__position._M_cur == this->_M_impl._M_finish._M_cur)
136 iterator __tmp = this->_M_impl._M_finish;
141 return _M_insert_aux(__position, __x);
144 #ifdef __GXX_EXPERIMENTAL_CXX0X__
145 template<typename _Tp, typename _Alloc>
146 template<typename... _Args>
147 typename deque<_Tp, _Alloc>::iterator
149 emplace(iterator __position, _Args&&... __args)
151 if (__position._M_cur == this->_M_impl._M_start._M_cur)
153 push_front(std::forward<_Args>(__args)...);
154 return this->_M_impl._M_start;
156 else if (__position._M_cur == this->_M_impl._M_finish._M_cur)
158 push_back(std::forward<_Args>(__args)...);
159 iterator __tmp = this->_M_impl._M_finish;
164 return _M_insert_aux(__position, std::forward<_Args>(__args)...);
168 template <typename _Tp, typename _Alloc>
169 typename deque<_Tp, _Alloc>::iterator
171 erase(iterator __position)
173 iterator __next = __position;
175 const difference_type __index = __position - begin();
176 if (static_cast<size_type>(__index) < (size() >> 1))
178 if (__position != begin())
179 _GLIBCXX_MOVE_BACKWARD3(begin(), __position, __next);
185 _GLIBCXX_MOVE3(__next, end(), __position);
188 return begin() + __index;
191 template <typename _Tp, typename _Alloc>
192 typename deque<_Tp, _Alloc>::iterator
194 erase(iterator __first, iterator __last)
196 if (__first == begin() && __last == end())
203 const difference_type __n = __last - __first;
204 const difference_type __elems_before = __first - begin();
205 if (static_cast<size_type>(__elems_before) <= (size() - __n) / 2)
207 if (__first != begin())
208 _GLIBCXX_MOVE_BACKWARD3(begin(), __first, __last);
209 _M_erase_at_begin(begin() + __n);
214 _GLIBCXX_MOVE3(__last, end(), __first);
215 _M_erase_at_end(end() - __n);
217 return begin() + __elems_before;
221 template <typename _Tp, class _Alloc>
222 template <typename _InputIterator>
225 _M_assign_aux(_InputIterator __first, _InputIterator __last,
226 std::input_iterator_tag)
228 iterator __cur = begin();
229 for (; __first != __last && __cur != end(); ++__cur, ++__first)
231 if (__first == __last)
232 _M_erase_at_end(__cur);
234 insert(end(), __first, __last);
237 template <typename _Tp, typename _Alloc>
240 _M_fill_insert(iterator __pos, size_type __n, const value_type& __x)
242 if (__pos._M_cur == this->_M_impl._M_start._M_cur)
244 iterator __new_start = _M_reserve_elements_at_front(__n);
247 std::__uninitialized_fill_a(__new_start, this->_M_impl._M_start,
248 __x, _M_get_Tp_allocator());
249 this->_M_impl._M_start = __new_start;
253 _M_destroy_nodes(__new_start._M_node,
254 this->_M_impl._M_start._M_node);
255 __throw_exception_again;
258 else if (__pos._M_cur == this->_M_impl._M_finish._M_cur)
260 iterator __new_finish = _M_reserve_elements_at_back(__n);
263 std::__uninitialized_fill_a(this->_M_impl._M_finish,
265 _M_get_Tp_allocator());
266 this->_M_impl._M_finish = __new_finish;
270 _M_destroy_nodes(this->_M_impl._M_finish._M_node + 1,
271 __new_finish._M_node + 1);
272 __throw_exception_again;
276 _M_insert_aux(__pos, __n, __x);
279 template <typename _Tp, typename _Alloc>
282 _M_fill_initialize(const value_type& __value)
287 for (__cur = this->_M_impl._M_start._M_node;
288 __cur < this->_M_impl._M_finish._M_node;
290 std::__uninitialized_fill_a(*__cur, *__cur + _S_buffer_size(),
291 __value, _M_get_Tp_allocator());
292 std::__uninitialized_fill_a(this->_M_impl._M_finish._M_first,
293 this->_M_impl._M_finish._M_cur,
294 __value, _M_get_Tp_allocator());
298 std::_Destroy(this->_M_impl._M_start, iterator(*__cur, __cur),
299 _M_get_Tp_allocator());
300 __throw_exception_again;
304 template <typename _Tp, typename _Alloc>
305 template <typename _InputIterator>
308 _M_range_initialize(_InputIterator __first, _InputIterator __last,
309 std::input_iterator_tag)
311 this->_M_initialize_map(0);
314 for (; __first != __last; ++__first)
320 __throw_exception_again;
324 template <typename _Tp, typename _Alloc>
325 template <typename _ForwardIterator>
328 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
329 std::forward_iterator_tag)
331 const size_type __n = std::distance(__first, __last);
332 this->_M_initialize_map(__n);
334 _Map_pointer __cur_node;
337 for (__cur_node = this->_M_impl._M_start._M_node;
338 __cur_node < this->_M_impl._M_finish._M_node;
341 _ForwardIterator __mid = __first;
342 std::advance(__mid, _S_buffer_size());
343 std::__uninitialized_copy_a(__first, __mid, *__cur_node,
344 _M_get_Tp_allocator());
347 std::__uninitialized_copy_a(__first, __last,
348 this->_M_impl._M_finish._M_first,
349 _M_get_Tp_allocator());
353 std::_Destroy(this->_M_impl._M_start,
354 iterator(*__cur_node, __cur_node),
355 _M_get_Tp_allocator());
356 __throw_exception_again;
360 // Called only if _M_impl._M_finish._M_cur == _M_impl._M_finish._M_last - 1.
361 template<typename _Tp, typename _Alloc>
362 #ifdef __GXX_EXPERIMENTAL_CXX0X__
363 template<typename... _Args>
366 _M_push_back_aux(_Args&&... __args)
370 _M_push_back_aux(const value_type& __t)
373 _M_reserve_map_at_back();
374 *(this->_M_impl._M_finish._M_node + 1) = this->_M_allocate_node();
377 #ifdef __GXX_EXPERIMENTAL_CXX0X__
378 this->_M_impl.construct(this->_M_impl._M_finish._M_cur,
379 std::forward<_Args>(__args)...);
381 this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __t);
383 this->_M_impl._M_finish._M_set_node(this->_M_impl._M_finish._M_node
385 this->_M_impl._M_finish._M_cur = this->_M_impl._M_finish._M_first;
389 _M_deallocate_node(*(this->_M_impl._M_finish._M_node + 1));
390 __throw_exception_again;
394 // Called only if _M_impl._M_start._M_cur == _M_impl._M_start._M_first.
395 template<typename _Tp, typename _Alloc>
396 #ifdef __GXX_EXPERIMENTAL_CXX0X__
397 template<typename... _Args>
400 _M_push_front_aux(_Args&&... __args)
404 _M_push_front_aux(const value_type& __t)
407 _M_reserve_map_at_front();
408 *(this->_M_impl._M_start._M_node - 1) = this->_M_allocate_node();
411 this->_M_impl._M_start._M_set_node(this->_M_impl._M_start._M_node
413 this->_M_impl._M_start._M_cur = this->_M_impl._M_start._M_last - 1;
414 #ifdef __GXX_EXPERIMENTAL_CXX0X__
415 this->_M_impl.construct(this->_M_impl._M_start._M_cur,
416 std::forward<_Args>(__args)...);
418 this->_M_impl.construct(this->_M_impl._M_start._M_cur, __t);
423 ++this->_M_impl._M_start;
424 _M_deallocate_node(*(this->_M_impl._M_start._M_node - 1));
425 __throw_exception_again;
429 // Called only if _M_impl._M_finish._M_cur == _M_impl._M_finish._M_first.
430 template <typename _Tp, typename _Alloc>
431 void deque<_Tp, _Alloc>::
434 _M_deallocate_node(this->_M_impl._M_finish._M_first);
435 this->_M_impl._M_finish._M_set_node(this->_M_impl._M_finish._M_node - 1);
436 this->_M_impl._M_finish._M_cur = this->_M_impl._M_finish._M_last - 1;
437 this->_M_impl.destroy(this->_M_impl._M_finish._M_cur);
440 // Called only if _M_impl._M_start._M_cur == _M_impl._M_start._M_last - 1.
441 // Note that if the deque has at least one element (a precondition for this
442 // member function), and if
443 // _M_impl._M_start._M_cur == _M_impl._M_start._M_last,
444 // then the deque must have at least two nodes.
445 template <typename _Tp, typename _Alloc>
446 void deque<_Tp, _Alloc>::
449 this->_M_impl.destroy(this->_M_impl._M_start._M_cur);
450 _M_deallocate_node(this->_M_impl._M_start._M_first);
451 this->_M_impl._M_start._M_set_node(this->_M_impl._M_start._M_node + 1);
452 this->_M_impl._M_start._M_cur = this->_M_impl._M_start._M_first;
455 template <typename _Tp, typename _Alloc>
456 template <typename _InputIterator>
459 _M_range_insert_aux(iterator __pos,
460 _InputIterator __first, _InputIterator __last,
461 std::input_iterator_tag)
462 { std::copy(__first, __last, std::inserter(*this, __pos)); }
464 template <typename _Tp, typename _Alloc>
465 template <typename _ForwardIterator>
468 _M_range_insert_aux(iterator __pos,
469 _ForwardIterator __first, _ForwardIterator __last,
470 std::forward_iterator_tag)
472 const size_type __n = std::distance(__first, __last);
473 if (__pos._M_cur == this->_M_impl._M_start._M_cur)
475 iterator __new_start = _M_reserve_elements_at_front(__n);
478 std::__uninitialized_copy_a(__first, __last, __new_start,
479 _M_get_Tp_allocator());
480 this->_M_impl._M_start = __new_start;
484 _M_destroy_nodes(__new_start._M_node,
485 this->_M_impl._M_start._M_node);
486 __throw_exception_again;
489 else if (__pos._M_cur == this->_M_impl._M_finish._M_cur)
491 iterator __new_finish = _M_reserve_elements_at_back(__n);
494 std::__uninitialized_copy_a(__first, __last,
495 this->_M_impl._M_finish,
496 _M_get_Tp_allocator());
497 this->_M_impl._M_finish = __new_finish;
501 _M_destroy_nodes(this->_M_impl._M_finish._M_node + 1,
502 __new_finish._M_node + 1);
503 __throw_exception_again;
507 _M_insert_aux(__pos, __first, __last, __n);
510 template<typename _Tp, typename _Alloc>
511 #ifdef __GXX_EXPERIMENTAL_CXX0X__
512 template<typename... _Args>
513 typename deque<_Tp, _Alloc>::iterator
515 _M_insert_aux(iterator __pos, _Args&&... __args)
517 value_type __x_copy(std::forward<_Args>(__args)...); // XXX copy
519 typename deque<_Tp, _Alloc>::iterator
521 _M_insert_aux(iterator __pos, const value_type& __x)
523 value_type __x_copy = __x; // XXX copy
525 difference_type __index = __pos - this->_M_impl._M_start;
526 if (static_cast<size_type>(__index) < size() / 2)
528 push_front(_GLIBCXX_MOVE(front()));
529 iterator __front1 = this->_M_impl._M_start;
531 iterator __front2 = __front1;
533 __pos = this->_M_impl._M_start + __index;
534 iterator __pos1 = __pos;
536 _GLIBCXX_MOVE3(__front2, __pos1, __front1);
540 push_back(_GLIBCXX_MOVE(back()));
541 iterator __back1 = this->_M_impl._M_finish;
543 iterator __back2 = __back1;
545 __pos = this->_M_impl._M_start + __index;
546 _GLIBCXX_MOVE_BACKWARD3(__pos, __back2, __back1);
548 *__pos = _GLIBCXX_MOVE(__x_copy);
552 template <typename _Tp, typename _Alloc>
555 _M_insert_aux(iterator __pos, size_type __n, const value_type& __x)
557 const difference_type __elems_before = __pos - this->_M_impl._M_start;
558 const size_type __length = this->size();
559 value_type __x_copy = __x;
560 if (__elems_before < difference_type(__length / 2))
562 iterator __new_start = _M_reserve_elements_at_front(__n);
563 iterator __old_start = this->_M_impl._M_start;
564 __pos = this->_M_impl._M_start + __elems_before;
567 if (__elems_before >= difference_type(__n))
569 iterator __start_n = (this->_M_impl._M_start
570 + difference_type(__n));
571 std::__uninitialized_move_a(this->_M_impl._M_start,
572 __start_n, __new_start,
573 _M_get_Tp_allocator());
574 this->_M_impl._M_start = __new_start;
575 _GLIBCXX_MOVE3(__start_n, __pos, __old_start);
576 std::fill(__pos - difference_type(__n), __pos, __x_copy);
580 std::__uninitialized_move_fill(this->_M_impl._M_start,
582 this->_M_impl._M_start,
584 _M_get_Tp_allocator());
585 this->_M_impl._M_start = __new_start;
586 std::fill(__old_start, __pos, __x_copy);
591 _M_destroy_nodes(__new_start._M_node,
592 this->_M_impl._M_start._M_node);
593 __throw_exception_again;
598 iterator __new_finish = _M_reserve_elements_at_back(__n);
599 iterator __old_finish = this->_M_impl._M_finish;
600 const difference_type __elems_after =
601 difference_type(__length) - __elems_before;
602 __pos = this->_M_impl._M_finish - __elems_after;
605 if (__elems_after > difference_type(__n))
607 iterator __finish_n = (this->_M_impl._M_finish
608 - difference_type(__n));
609 std::__uninitialized_move_a(__finish_n,
610 this->_M_impl._M_finish,
611 this->_M_impl._M_finish,
612 _M_get_Tp_allocator());
613 this->_M_impl._M_finish = __new_finish;
614 _GLIBCXX_MOVE_BACKWARD3(__pos, __finish_n, __old_finish);
615 std::fill(__pos, __pos + difference_type(__n), __x_copy);
619 std::__uninitialized_fill_move(this->_M_impl._M_finish,
620 __pos + difference_type(__n),
622 this->_M_impl._M_finish,
623 _M_get_Tp_allocator());
624 this->_M_impl._M_finish = __new_finish;
625 std::fill(__pos, __old_finish, __x_copy);
630 _M_destroy_nodes(this->_M_impl._M_finish._M_node + 1,
631 __new_finish._M_node + 1);
632 __throw_exception_again;
637 template <typename _Tp, typename _Alloc>
638 template <typename _ForwardIterator>
641 _M_insert_aux(iterator __pos,
642 _ForwardIterator __first, _ForwardIterator __last,
645 const difference_type __elemsbefore = __pos - this->_M_impl._M_start;
646 const size_type __length = size();
647 if (static_cast<size_type>(__elemsbefore) < __length / 2)
649 iterator __new_start = _M_reserve_elements_at_front(__n);
650 iterator __old_start = this->_M_impl._M_start;
651 __pos = this->_M_impl._M_start + __elemsbefore;
654 if (__elemsbefore >= difference_type(__n))
656 iterator __start_n = (this->_M_impl._M_start
657 + difference_type(__n));
658 std::__uninitialized_move_a(this->_M_impl._M_start,
659 __start_n, __new_start,
660 _M_get_Tp_allocator());
661 this->_M_impl._M_start = __new_start;
662 _GLIBCXX_MOVE3(__start_n, __pos, __old_start);
663 std::copy(__first, __last, __pos - difference_type(__n));
667 _ForwardIterator __mid = __first;
668 std::advance(__mid, difference_type(__n) - __elemsbefore);
669 std::__uninitialized_move_copy(this->_M_impl._M_start,
670 __pos, __first, __mid,
672 _M_get_Tp_allocator());
673 this->_M_impl._M_start = __new_start;
674 std::copy(__mid, __last, __old_start);
679 _M_destroy_nodes(__new_start._M_node,
680 this->_M_impl._M_start._M_node);
681 __throw_exception_again;
686 iterator __new_finish = _M_reserve_elements_at_back(__n);
687 iterator __old_finish = this->_M_impl._M_finish;
688 const difference_type __elemsafter =
689 difference_type(__length) - __elemsbefore;
690 __pos = this->_M_impl._M_finish - __elemsafter;
693 if (__elemsafter > difference_type(__n))
695 iterator __finish_n = (this->_M_impl._M_finish
696 - difference_type(__n));
697 std::__uninitialized_move_a(__finish_n,
698 this->_M_impl._M_finish,
699 this->_M_impl._M_finish,
700 _M_get_Tp_allocator());
701 this->_M_impl._M_finish = __new_finish;
702 _GLIBCXX_MOVE_BACKWARD3(__pos, __finish_n, __old_finish);
703 std::copy(__first, __last, __pos);
707 _ForwardIterator __mid = __first;
708 std::advance(__mid, __elemsafter);
709 std::__uninitialized_copy_move(__mid, __last, __pos,
710 this->_M_impl._M_finish,
711 this->_M_impl._M_finish,
712 _M_get_Tp_allocator());
713 this->_M_impl._M_finish = __new_finish;
714 std::copy(__first, __mid, __pos);
719 _M_destroy_nodes(this->_M_impl._M_finish._M_node + 1,
720 __new_finish._M_node + 1);
721 __throw_exception_again;
726 template<typename _Tp, typename _Alloc>
729 _M_destroy_data_aux(iterator __first, iterator __last)
731 for (_Map_pointer __node = __first._M_node + 1;
732 __node < __last._M_node; ++__node)
733 std::_Destroy(*__node, *__node + _S_buffer_size(),
734 _M_get_Tp_allocator());
736 if (__first._M_node != __last._M_node)
738 std::_Destroy(__first._M_cur, __first._M_last,
739 _M_get_Tp_allocator());
740 std::_Destroy(__last._M_first, __last._M_cur,
741 _M_get_Tp_allocator());
744 std::_Destroy(__first._M_cur, __last._M_cur,
745 _M_get_Tp_allocator());
748 template <typename _Tp, typename _Alloc>
751 _M_new_elements_at_front(size_type __new_elems)
753 if (this->max_size() - this->size() < __new_elems)
754 __throw_length_error(__N("deque::_M_new_elements_at_front"));
756 const size_type __new_nodes = ((__new_elems + _S_buffer_size() - 1)
758 _M_reserve_map_at_front(__new_nodes);
762 for (__i = 1; __i <= __new_nodes; ++__i)
763 *(this->_M_impl._M_start._M_node - __i) = this->_M_allocate_node();
767 for (size_type __j = 1; __j < __i; ++__j)
768 _M_deallocate_node(*(this->_M_impl._M_start._M_node - __j));
769 __throw_exception_again;
773 template <typename _Tp, typename _Alloc>
776 _M_new_elements_at_back(size_type __new_elems)
778 if (this->max_size() - this->size() < __new_elems)
779 __throw_length_error(__N("deque::_M_new_elements_at_back"));
781 const size_type __new_nodes = ((__new_elems + _S_buffer_size() - 1)
783 _M_reserve_map_at_back(__new_nodes);
787 for (__i = 1; __i <= __new_nodes; ++__i)
788 *(this->_M_impl._M_finish._M_node + __i) = this->_M_allocate_node();
792 for (size_type __j = 1; __j < __i; ++__j)
793 _M_deallocate_node(*(this->_M_impl._M_finish._M_node + __j));
794 __throw_exception_again;
798 template <typename _Tp, typename _Alloc>
801 _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front)
803 const size_type __old_num_nodes
804 = this->_M_impl._M_finish._M_node - this->_M_impl._M_start._M_node + 1;
805 const size_type __new_num_nodes = __old_num_nodes + __nodes_to_add;
807 _Map_pointer __new_nstart;
808 if (this->_M_impl._M_map_size > 2 * __new_num_nodes)
810 __new_nstart = this->_M_impl._M_map + (this->_M_impl._M_map_size
811 - __new_num_nodes) / 2
812 + (__add_at_front ? __nodes_to_add : 0);
813 if (__new_nstart < this->_M_impl._M_start._M_node)
814 std::copy(this->_M_impl._M_start._M_node,
815 this->_M_impl._M_finish._M_node + 1,
818 std::copy_backward(this->_M_impl._M_start._M_node,
819 this->_M_impl._M_finish._M_node + 1,
820 __new_nstart + __old_num_nodes);
824 size_type __new_map_size = this->_M_impl._M_map_size
825 + std::max(this->_M_impl._M_map_size,
828 _Map_pointer __new_map = this->_M_allocate_map(__new_map_size);
829 __new_nstart = __new_map + (__new_map_size - __new_num_nodes) / 2
830 + (__add_at_front ? __nodes_to_add : 0);
831 std::copy(this->_M_impl._M_start._M_node,
832 this->_M_impl._M_finish._M_node + 1,
834 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
836 this->_M_impl._M_map = __new_map;
837 this->_M_impl._M_map_size = __new_map_size;
840 this->_M_impl._M_start._M_set_node(__new_nstart);
841 this->_M_impl._M_finish._M_set_node(__new_nstart + __old_num_nodes - 1);
844 // Overload for deque::iterators, exploiting the "segmented-iterator
845 // optimization". NB: leave const_iterators alone!
846 template<typename _Tp>
848 fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>& __first,
849 const _Deque_iterator<_Tp, _Tp&, _Tp*>& __last, const _Tp& __value)
851 typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
853 for (typename _Self::_Map_pointer __node = __first._M_node + 1;
854 __node < __last._M_node; ++__node)
855 std::fill(*__node, *__node + _Self::_S_buffer_size(), __value);
857 if (__first._M_node != __last._M_node)
859 std::fill(__first._M_cur, __first._M_last, __value);
860 std::fill(__last._M_first, __last._M_cur, __value);
863 std::fill(__first._M_cur, __last._M_cur, __value);
866 _GLIBCXX_END_NESTED_NAMESPACE