45template <
class _TypeT,
class _Allocator>
46deque<_TypeT, _Allocator>&
47deque<_TypeT, _Allocator>::
48operator= (
const deque &__rhs)
53 const size_type __size =
size ();
55 if (__size < __rhs.size ()) {
56 const const_iterator __mid = __rhs.begin () + __size;
58 _STD::copy (__mid, __rhs.end (),
59 _STD::inserter (*
this, _STD::copy (__rhs.begin (), __mid,
63 erase (_STD::copy (__rhs.begin (), __rhs.end (), begin ()),
end ());
69template <
class _TypeT,
class _Allocator>
70typename deque<_TypeT, _Allocator>::iterator
71deque<_TypeT, _Allocator>::
72insert (iterator __it, const_reference __x)
77 if (__it == begin ()) {
88 const size_type __inx =
_DISTANCE (begin (), __it, size_type);
92 if (__inx <
size () - __inx) {
93 push_front (front ());
94 _STD::copy (begin () + 2, begin () + (__inx + 1), begin () + 1);
99 _STD::copy_backward (begin () + __inx,
end () - 2,
end () - 1);
102 __it = begin () + __inx;
110template <
class _TypeT,
class _Allocator>
111typename deque<_TypeT, _Allocator>::iterator
112deque<_TypeT, _Allocator>::
121 const iterator __next = ++iterator (__it);
123 if (__it - begin () <
end () - __it) {
125 _STD::copy_backward (begin (), __it, __next);
129 return empty () ?
end () : __next;
132 _STD::copy (__next,
end (), __it);
140template <
class _TypeT,
class _Allocator>
141typename deque<_TypeT, _Allocator>::iterator
142deque<_TypeT, _Allocator>::
143erase (iterator __first, iterator __last)
151 size_type __n =
_DISTANCE (__first, __last, size_type);
155 if (__first - begin () <
end () - __last) {
157 _STD::copy_backward (begin (), __first, __last);
165 _STD::copy (__last,
end (), __first);
174template <
class _TypeT,
class _Allocator>
175void deque<_TypeT, _Allocator>::
176swap (deque<_TypeT, _Allocator> &__rhs)
181 if (get_allocator () == __rhs.get_allocator ()) {
183 _STD::swap (_C_beg, __rhs._C_beg);
184 _STD::swap (_C_end, __rhs._C_end);
185 _STD::swap (_C_nodes, __rhs._C_nodes);
186 _STD::swap (_C_node_size, __rhs._C_node_size);
188 if (pointer() == _C_beg._C_cur) {
191 && _C_end._C_node == &__rhs._C_end._C_cur);
194 _C_end._C_node = &_C_end._C_cur;
200 if (pointer() == __rhs._C_beg._C_cur) {
203 && __rhs._C_end._C_node == &_C_end._C_cur);
205 __rhs._C_beg._C_node =
206 __rhs._C_end._C_node = &__rhs._C_end._C_cur;
220template <
class _TypeT,
class _Allocator>
221void deque<_TypeT, _Allocator>::
222_C_push (
bool __at_back, const_reference __x)
226 const size_type __bufsize = _C_bufsize ();
228 _C_value_alloc_type __alloc (*
this);
231 const pointer __buf = __alloc.allocate (__bufsize, pointer ());
233 const bool __empty = empty ();
236 || (__at_back && _C_end._C_node == _C_nodes + _C_node_size - 1)
237 || (!__at_back && _C_beg._C_node == _C_nodes)) {
239 _C_node_alloc_type __node_alloc (*
this);
246 const _C_node_pointer __end = _C_end._C_node + !__empty;
248 const size_type __nodes = size_type (__end - _C_beg._C_node);
251 const size_type __nvecsize = _C_vecsize (__nodes);
256 const _C_node_pointer __ovec = _C_nodes - !__empty;
257 _C_node_pointer __nvec;
261 __nvec = __node_alloc.allocate (__nvecsize + 2, __ovec);
265 const pointer __where = __buf
266 + ( __empty ? __bufsize / 2 - !__at_back
267 : __at_back ? 0 : __bufsize - 1);
270 __alloc.construct (__where, __x);
273 __node_alloc.deallocate (__nvec, __nvecsize + 2);
282 __alloc.deallocate (__buf, __bufsize);
288 const size_type __beg_inx = __nvecsize / (__empty ? 2 : 4);
289 const size_type __end_inx = __beg_inx + __nodes;
292 _STD::copy (_C_beg._C_node, __end, __nvec + (__beg_inx + !__at_back));
296 if (!(__ovec == _C_node_pointer ()))
297 __node_alloc.deallocate (__ovec, _C_node_size + 2);
301 _C_node_size = __nvecsize;
307 _C_nodes [__end_inx] = __buf;
309 _C_beg._C_node = _C_nodes + __beg_inx;
310 _C_end = _C_deque_iter (__buf, _C_nodes + __end_inx);
315 _C_nodes [__beg_inx] = __buf;
317 _C_beg = _C_deque_iter (__buf + __bufsize, _C_nodes + __beg_inx);
318 _C_end._C_node = _C_nodes + __end_inx;
325 _C_end._C_cur = __buf + __bufsize / 2;
334 __alloc.construct (__buf, __x);
339 *++_C_end._C_node = __buf;
340 _C_end._C_cur = __buf;
343 __alloc.construct (__buf + (__bufsize - 1), __x);
348 *--_C_beg._C_node = __buf;
349 _C_beg._C_cur = __buf + __bufsize;
353 __alloc.deallocate (__buf, __bufsize);
359 _C_end._C_node [+1] = pointer ();
360 _C_beg._C_node [-1] = pointer ();
364template <
class _TypeT,
class _Allocator>
365void deque<_TypeT, _Allocator>::
368 const size_type __bufsize = _C_bufsize ();
371 deallocate (*_C_beg._C_node, __bufsize));
373 _C_node_alloc_type (*this).
374 deallocate (_C_nodes - 1, _C_node_size + 2);
378 *_C_beg._C_node++ = pointer ();
379 _C_beg = _C_deque_iter (*_C_beg._C_node, _C_beg._C_node);
384template <
class _TypeT,
class _Allocator>
385void deque<_TypeT, _Allocator>::
388 const size_type __bufsize = _C_bufsize ();
391 deallocate (*_C_end._C_node, __bufsize));
393 _C_node_alloc_type (*this).
394 deallocate (_C_nodes - 1, _C_node_size + 2);
398 *_C_end._C_node-- = pointer ();
399 _C_end = _C_deque_iter (*_C_end._C_node + __bufsize, _C_end._C_node);
404template <
class _TypeT,
class _Allocator>
405void deque<_TypeT, _Allocator>::
406_C_assign_n (size_type __n, const_reference __x)
410#ifndef _RWSTD_NO_EXT_DEQUE_ASSIGN_IN_PLACE
421 const iterator __end =
end ();
426 for (iterator __ix = begin (); !(__ix == __end); ++__ix, --__n) {
427 if (size_type () == __n) {
434 insert (__end, __n, __x);
444 insert (begin (), __n, __x);
451template <
class _TypeT,
class _Allocator>
452void deque<_TypeT, _Allocator>::
453_C_insert_n (
const iterator &__it, size_type __n, const_reference __x)
458 const size_type __inx =
_DISTANCE (begin (), __it, size_type);
459 const size_type __rem =
size () - __inx;
469 for (size_type __i = __n - __inx; __i; --__i)
472 for (size_type __j = __inx; __j; --__j)
473 push_front (*(begin () + (__n - 1)));
475 _STD::fill (begin () + __n, begin () + (__n + __inx), __x);
479 for (size_type __i = __n; __i; --__i)
480 push_front (*(begin () + __n - 1));
482 const iterator __tmp = begin () + __n;
484 _STD::copy (__tmp + __n, __tmp + __inx, __tmp);
486 _STD::fill (begin () + __inx, __tmp + __inx, __x);
493 const size_type __size0 =
size ();
497 for (size_type __i = __n - __rem; __i; --__i)
500 for (size_type __j = 0; __j != __rem; ++__j)
501 push_back (*(begin () + (__inx + __j)));
503 _STD::fill (begin () + __inx, begin () + __size0, __x);
507 for (size_type __i = 0;__i != __n; ++__i)
508 push_back (*(begin () + __size0 - __n + __i));
510 const iterator __tmp = begin () + __inx;
512 _STD::copy_backward (__tmp, begin () + __size0 - __n,
515 _STD::fill (__tmp, __tmp + __n, __x);
521template <
class _TypeT,
class _Allocator>
522template <
class _InputIter>
523void deque<_TypeT, _Allocator>::
524_C_assign_range (_InputIter __first, _InputIter __last, input_iterator_tag)
526 typedef deque _Deque;
531#ifndef _RWSTD_NO_EXT_DEQUE_ASSIGN_IN_PLACE
542 const iterator __end = this->
end ();
547 for (iterator __ix = this->begin (); !(__ix == __end);
549 if (__first == __last) {
550 this->erase (__ix, __end);
556 this->insert (__end, __first, __last);
566 this->insert (this->begin (), __first, __last);
573template<
class _TypeT,
class _Allocator>
574template <
class _InputIter>
575void deque<_TypeT, _Allocator>::
576_C_insert_range (iterator __it,
577 _InputIter __first, _InputIter __last,
580 typedef deque _Deque;
585#ifndef _RWSTD_NO_EXT_DEQUE_INSERT_IN_PLACE
590 for ( ; !(__first == __last); ++__it, ++__first)
591 __it = this->insert (__it, *__first);
598 _Deque __tmp (this->begin (), __it, this->get_allocator ());
600 for (; !(__first == __last); ++__first)
601 __tmp.push_back (*__first);
603 __tmp.insert (__tmp.end (), __it, this->
end ());
626template <
class _TypeT,
class _Allocator>
627template <
class _B
idirIter>
628void deque<_TypeT, _Allocator>::
629_C_insert_range (iterator __it,
630 _BidirIter __first, _BidirIter __last,
631 bidirectional_iterator_tag)
633 typedef deque _Deque;
642 const size_type __sz0 = this->
size ();
643 const size_type __inx =
_DISTANCE (this->begin (), __it, size_type);
644 const size_type __rem = __sz0 - __inx;
645 const size_type __n =
_DISTANCE (__first, __last, size_type);
659 _BidirIter __from (__last);
661 _STD::advance (__from, -difference_type (__inx));
663 const _BidirIter __mid (__from);
665 while (!(__from == __first))
666 this->push_front (*--__from);
668 for (size_type __i = __inx; __i; --__i)
669 this->push_front (*(this->begin () + (__n - 1)));
671 _STD::copy (__mid, __last, this->begin () + __n);
679 for (size_type __i = __n; __i; --__i)
680 this->push_front (*(this->begin () + (__n - 1)));
682 const iterator __to = this->begin () + __n;
684 _STD::copy (__to + __n, __to + __inx, __to);
685 _STD::copy (__first, __last, this->begin () + __inx);
693 _BidirIter __from (__first);
695 _STD::advance (__from, __rem);
697 const _BidirIter __to (__from);
699 for ( ; !(__from == __last); ++__from)
700 this->push_back (*__from);
702 for (size_type __i = 0; __i != __rem; ++__i)
703 this->push_back (*(this->begin () + (__inx + __i)));
705 _STD::copy (__first, __to, this->begin () + __inx);
708 for (size_type __i = 0; __i != __n; ++__i)
709 this->push_back (*(this->begin () + (__sz0 - __n + __i)));
711 const iterator __to = this->begin () + __sz0;
712 const iterator __from = this->begin () + __inx;
713 const iterator __from_end = this->begin () + (__sz0 - __n);
715 _STD::copy_backward (__from, __from_end, __to);
716 _STD::copy (__first, __last, __from);
722template<
class _TypeT,
class _Allocator>
723bool deque<_TypeT, _Allocator>::
724_C_is_valid (
int __emptyfl)
const
729 return _C_is_valid (0 + empty ());
733 if (_C_node_pointer () != _C_nodes) {
756 const size_type __bufsize = _C_bufsize ();
777 _RWSTD_ASSERT (_C_beg._C_cur <= *_C_beg._C_node + __bufsize);
788 _RWSTD_ASSERT (_C_end._C_cur <= *_C_end._C_node + __bufsize);
#define _RWSTD_VALUE_ALLOC(ignore, object, call)
#define _RWSTD_UNUSED(arg)
#define _RWSTD_NAMESPACE(name)
#define _RWSTD_ASSERT(ignore)
#define _DISTANCE(first, last, ignore)
#define _RWSTD_ASSERT_RANGE(ign1, ign2)