Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
vector.cc
Go to the documentation of this file.
1
43
44template <class _TypeT, class _Allocator>
45vector<_TypeT, _Allocator>&
46vector<_TypeT, _Allocator>::
47operator= (const vector &__rhs)
48{
49#ifndef _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
50
51 if (capacity () < __rhs.size ())
52 vector (__rhs).swap (*this);
53 else if (&__rhs != this)
54 assign (__rhs.begin (), __rhs.end ());
55
56#else // if defined (_RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE)
57
58 vector (__rhs).swap (*this);
59
60#endif // _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
61
62 return *this;
63}
64
65
66template <class _TypeT, class _Allocator>
67void
68vector<_TypeT, _Allocator>::
69_C_realloc (size_type __n)
70{
71 const size_type __max_size = max_size ();
72
73 // compute the new capacity from the greater of the current size
74 // and the requested size, but no greater than max_size()
75 size_type __cap = _RWSTD_NEW_CAPACITY (vector, this, (max)(size (), __n));
76
77 // do not exceed max_size()
78 if (__max_size < __cap)
79 __cap = __max_size;
80
81 // create an empty temporary vector
82 vector __tmp (get_allocator ());
83
84 // allocate storage of requested capacity
85 __tmp._C_alloc._C_begin = _C_alloc.allocate (__cap, this);
86
87 // initialize pointers
88 __tmp._C_alloc._C_end = __tmp._C_alloc._C_begin;
89 __tmp._C_alloc._C_bufend = __tmp._C_alloc._C_begin + __cap;
90
91 // copy *this into the temporary one element at a time, as if
92 // by calling std::unitialized_copy(), growing the temporary
93 // at each iteration so that an exception thrown by the copy
94 // ctor will cause the destruction of all already constructed
95 // elements (by invoking the temporary's dtor)
96 for (pointer __ptr = _C_alloc._C_begin; !(__ptr == _C_alloc._C_end);
97 ++__ptr) {
98 __tmp._C_push_back (*__ptr);
99 }
100
101 // swap *this with the temporary, having its dtor clean up
102 swap (__tmp);
103}
104
105
106template <class _TypeT, class _Allocator>
107void vector<_TypeT, _Allocator>::
108_C_destroy (iterator __first)
109{
110 _RWSTD_ASSERT_RANGE (__first, end ());
111
112 for (size_type __n = end () - __first; !(0 == __n); --__n)
113 _C_alloc.destroy (--_C_alloc._C_end);
114}
115
116
117template <class _TypeT, class _Allocator>
118void vector<_TypeT, _Allocator>::
119_C_unsafe_swap (vector &__other)
120{
121 // called only from vector::swap() for unequal allocators
122 _RWSTD_ASSERT (!(get_allocator () == __other.get_allocator ()));
123
124 // avoid passing the whole object to other vector member
125 // functions (i.e., assign()) in case they are implemented
126 // in terms of swap(); use iterators instead
127
128 vector __tmp (__other.get_allocator ());
129
130 // assert that the copy of the allocator compares equal
131 // to the original (otherwise the swap() below will cause
132 // a recursive call)
133 _RWSTD_ASSERT (__tmp.get_allocator () == __other.get_allocator ());
134
135 __tmp.assign (begin (), end ());
136 assign (__other.begin (), __other.end ());
137 __other.swap (__tmp);
138}
139
140
141template <class _TypeT, class _Allocator>
142void vector<_TypeT, _Allocator>::
143_C_assign_n (size_type __n, const_reference __x)
144{
145#ifndef _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
146
147 // FIXME: implement in-place assignment with repetition
148
149 clear ();
150 insert (begin (), __n, __x);
151
152#else // if defined (_RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE)
153
154 clear ();
155 insert (begin (), __n, __x);
156
157#endif // _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
158}
159
160
161template <class _TypeT, class _Allocator>
162void vector<_TypeT, _Allocator>::
163_C_insert_1 (const iterator &__it, const_reference __x)
164{
165 _RWSTD_ASSERT_RANGE (begin (), __it);
166
167 if (size () < capacity ()) {
168
169 if (__it < end ()) {
170
171 const pointer __end = _C_alloc._C_end;
172
173 // construct a copy of the last element in the range [it, end)
174 // in the uninitialized slot just past the end of the range
175 // and bump up end()
176 _C_push_back (*(_C_alloc._C_end - difference_type (1)));
177
178 // move the remaining elements from the range above one slot
179 // toward the end starting with the last element
180 _STD::copy_backward (__it, end () - 2, __end);
181
182 // overwrite the element at the given position
183 *__it = __x;
184 }
185 else {
186 // construct a copy of the value to be inserted
187 // in the uninitialized slot
188 _C_push_back (__x);
189 }
190 }
191 else {
192 _C_insert_n (__it, size_type (1), __x);
193 }
194}
195
196
197template <class _TypeT, class _Allocator>
198void vector<_TypeT, _Allocator>::
199_C_insert_n (const iterator &__it, size_type __n, const_reference __x)
200{
201 _RWSTD_ASSERT_RANGE (begin (), __it);
202
203 if (!__n)
204 return;
205
206 // 23.2.4.2, p5: calls to insert() must not reallocate storage
207 // unless the new size of the container would exceed its capacity
208
209 // compute the numbers of elements to be copied and inserted
210 const size_type __size1 = _DISTANCE (begin (), __it, size_type);
211 const size_type __size2 = size () + __n;
212
213 if (capacity () < __size2) {
214
215 // allocate a temporary vector large enough to hold all elements
216 vector __tmp (get_allocator ());
217 __tmp.reserve (__size2);
218
219 _RWSTD_ASSERT (!(pointer () == __tmp._C_alloc._C_end));
220
221 iterator __i;
222
223 // copy the initial range prior to `it' as if by a call to
224 // uninitialized_copy (begin (), __it, __tmp._C_alloc._C_begin);
225 for (__i = begin (); !(__i == __it); ++__i) {
226
227 _RWSTD_ASSERT (!( __tmp._C_alloc._C_end
228 == __tmp._C_alloc._C_bufend));
229
230 __tmp._C_push_back (*__i);
231 }
232
233 // construct `n' copies of `x' just past the initial range,
234 // as if by a call to
235 // uninitialized_fill_n (__tmp._C_aloc._C_begin + __size1, __n, __x);
236 for ( ; __n; --__n) {
237
238 _RWSTD_ASSERT (!( __tmp._C_alloc._C_end
239 == __tmp._C_alloc._C_bufend));
240
241 __tmp._C_push_back (__x);
242 }
243
244 // copy the final range of elements starting with `it'
245 // as if by a call to
246 // uninitialized_copy (__it, end (),
247 // __tmp._C_alloc._C_begin + __size1 + __n);
248
249 for (__i = __it; !(__i == end ()); ++__i) {
250
251 _RWSTD_ASSERT (!( __tmp._C_alloc._C_end
252 == __tmp._C_alloc._C_bufend));
253
254 __tmp._C_push_back (*__i);
255 }
256
257 // swap the sequences controlled by the temporary vector and *this
258 __tmp.swap (*this);
259
260 return;
261 }
262
263 // compute the beginning of the range of elements in the sequence
264 // controlled by *this that need to be moved (copy contructed past
265 // the end of the end of the sequence or assigned over existing
266 // elements)
267 const pointer __movbeg = _C_alloc._C_begin + __size1;
268 const pointer __movend = __movbeg + __n;
269
270 _RWSTD_ASSERT (_C_make_iter (__movbeg) == __it);
271
272 if (__movend <= _C_alloc._C_end) {
273
274 // the end of the range of existing elements after being
275 // moved to make room for the elements to be inserted is
276 // before the current end of the sequence
277
278 // compute the beginning of the range of elements whose copies
279 // will be constructed just past the current end of the sequence
280 const pointer __ucpbeg = _C_alloc._C_end - __n;
281 const pointer __ucpend = _C_alloc._C_end;
282
283 // construct copies of elements that will be moved beyond
284 // the current end of the sequence controlled by *this
285 _STD::uninitialized_copy (__ucpbeg, _C_alloc._C_end,
286 _C_alloc._C_end, _C_alloc);
287
288 // advance end to maintain consistent state
289 _C_alloc._C_end += __n;
290
291 // copy elements the will be overwritten below
292 // over the range of elements moved above
293 _STD::copy_backward (__movbeg, __ucpbeg, __ucpend);
294 }
295 else {
296
297 // compute the length of the initial subsequence of the range
298 // of element being inserted that overlaps the end of the
299 // sequence being inserted into
300 const size_type __n1 = size () - __size1;
301 const size_type __n2 = __n - __n1;
302
303 _STD::uninitialized_fill_n (_C_alloc._C_end, __n2, __x, _C_alloc);
304
305 const pointer __end = _C_alloc._C_end;
306
307 _C_alloc._C_end += __n2;
308
309 // construct copies of the range of elements [pos, end)
310 // past the end of the range of elements inserted above
311 _STD::uninitialized_copy (__movbeg, __end, _C_alloc._C_end, _C_alloc);
312
313 _C_alloc._C_end += __end - __movbeg;
314
315 __n = __n1;
316 }
317
318 _STD::fill_n (__movbeg, __n, __x);
319}
320
321
322template<class _TypeT, class _Allocator>
323template<class _InputIter>
324void vector<_TypeT, _Allocator>::
325_C_assign_range (_InputIter __first, _InputIter __last, input_iterator_tag)
326{
327 _RWSTD_ASSERT_RANGE (__first, __last);
328
329#ifndef _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
330
331 // assign over existing elements for better efficiency
332 // and exception safety
333
334 // complexity: linear in distance(first, last)
335 // -- exactly A=min(size(), distance(first, last)) calls
336 // to value_type's assignment operator
337 // -- exactly (max(size(), distance(first, last)) - A)
338 // calls to value_type's copy ctor
339 //
340 // exception safety:
341 // -- nothrow if size() >= distance(first, last), and value_type's
342 // assignment operator and iterator operations do not throw
343 // -- basic otherwise
344
345 const iterator __end = this->end ();
346
347 for (iterator __it = this->begin (); __it != __end; ++__it, ++__first) {
348 if (__first == __last) {
349 this->erase (__it, __end);
350 return;
351 }
352 *__it = *__first;
353 }
354
355 this->insert (__end, __first, __last);
356
357#else // if defined (_RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE)
358
359 // follow the inefficient requirement in 23.2.4.1, p2
360
361 // complexity: linear in distance(first, last)
362 // exactly distance(first, last) calls to value_type's copy ctor
363 // exception safety: basic
364
365 this->clear ();
366 this->insert (this->begin (), __first, __last);
367
368#endif // _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
369
370}
371
372
373template <class _TypeT, class _Allocator>
374template <class _FwdIter>
375void vector<_TypeT, _Allocator>::
376_C_assign_range (_FwdIter __first, _FwdIter __last, forward_iterator_tag)
377{
378 _RWSTD_ASSERT_RANGE (__first, __last);
379
380#ifndef _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
381
382 // assign over existing elements for better efficiency
383 // and exception safety
384
385 // complexity: linear in distance(first, last)
386 // exception safety:
387 // -- nothrow if size() >= distance(first, last), and value_type's
388 // assignment operator and iterator operations do not throw
389 // -- strong if capacity() < size() + distance(first, last)
390 // -- basic otherwise
391
392 const size_type __size1 = _DISTANCE (__first, __last, size_type);
393 const size_type __size2 = this->size () + __size1;
394
395 if (this->capacity () < __size2) {
396
397 // exception safety: strong
398
399 vector<value_type, allocator_type> __tmp (this->get_allocator ());
400 __tmp.reserve (__size2);
401
402 // copy elements in the range [first, last) into the temporary
403 // one element at a time, as if by calling
404 // std::unitialized_copy(), growing the temporary at each
405 // iteration so that an exception thrown by the copy ctor will
406 // cause the destruction of all already constructed elements
407 // (by invoking the temporary's dtor)
408 for ( ; !(__first == __last); ++__first)
409 __tmp._C_push_back (*__first);
410
411 // swap *this with the temporary, having its dtor clean up
412 this->swap (__tmp);
413 }
414 else {
415 // exception safety: nothrow or basic
416
417 const iterator __end = this->end ();
418
419 for (iterator __i = this->begin (); __i != __end; ++__i, ++__first) {
420 if (__first == __last) {
421 this->erase (__i, __end);
422 return;
423 }
424 *__i = *__first;
425 }
426
427 this->insert (__end, __first, __last);
428 }
429
430#else // if defined (_RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE)
431
432 // follow the inefficient requirement in 23.2.4.1, p2
433
434 // complexity: linear in distance(first, last)
435 // exception safety: basic
436
437 this->clear ();
438 this->insert (this->begin (), __first, __last);
439
440#endif // _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
441
442}
443
444
445template <class _TypeT, class _Allocator>
446template <class _InputIter>
447void vector<_TypeT, _Allocator>::
448_C_insert_range (iterator __it, _InputIter __first, _InputIter __last,
449 input_iterator_tag)
450{
451 _RWSTD_ASSERT_RANGE (__it, end ());
452 _RWSTD_ASSERT_RANGE (__first, __last);
453
454#ifndef _RWSTD_NO_EXT_VECTOR_INSERT_IN_PLACE
455
456 // note that this extension does not satisfy the strong exception
457 // safety requirement in 23.2.4.3, p1
458
459 // complexity: linear in distance(first, last)
460 // exception safety: basic
461
462 // append one element at a time to prevent the loss of data
463 // from the input sequence in the case of an exception
464
465 const size_type __size = this->size ();
466 const size_type __inx = _DISTANCE (this->begin (), __it, size_type);
467
468 _RWSTD_ASSERT (__inx <= __size);
469
470 for (; !(__first == __last); ++__first)
471 this->push_back (*__first);
472
473 if (__inx < __size) {
474 // swap the inserted elements with the elements before which
475 // they should be inserted, as if by calling
476 // std::rotate (__beg, __mid, _C_alloc._C_end)
477 const pointer __beg = this->_C_alloc._C_begin + __inx;
478 const pointer __mid = this->_C_alloc._C_begin + __size;
479
480 if (__beg < __mid) {
481 for (pointer __p0 = __beg, __p1 = __mid; __p0 < --__p1; ++__p0)
482 _STD::iter_swap (__p0, __p1);
483 }
484
485 if (__mid < this->_C_alloc._C_end) {
486 for (pointer __p0 = __mid, __p1 = this->_C_alloc._C_end;
487 __p0 < --__p1; ++__p0)
488 _STD::iter_swap (__p0, __p1);
489 }
490
491 if (__beg < this->_C_alloc._C_end) {
492 for (pointer __p0 = __beg, __p1 = this->_C_alloc._C_end;
493 __p0 < --__p1; ++__p0)
494 _STD::iter_swap (__p0, __p1);
495 }
496 }
497
498#else // if defined (_RWSTD_NO_EXT_VECTOR_INSERT_IN_PLACE)
499
500 // 23.2.4.3, p1: If an exception is thrown other than by the copy
501 // constructor or assignment operator of T there are no effects.
502 // see also lwg issue 406
503
504 // complexity: linear in distance(first, last)
505 // exception safety:
506 // -- strong if capacity() < size() + distance(first, last) and
507 // value_type's assignment operator and copy ctor do not throw
508 // -- basic otherwise
509
510 // insert input range into a temporary sequence rather than into *this
511 // to coid modifying *this in case an exception (e.g., bad_alloc) is
512 // thrown
513 vector<value_type, allocator_type> __tmp (this->get_allocator ());
514
515 for ( ; !(__first == __last); ++__first)
516 __tmp.push_back (*__first);
517
518 // insert into *this using a more efficient algorithm optimized
519 // for BidirectionalIterator (and better)
520 this->insert (__it, __tmp.begin (), __tmp.end ());
521
522#endif // _RWSTD_NO_EXT_VECTOR_INSERT_IN_PLACE
523
524}
525
526
527template <class _TypeT, class _Allocator>
528template <class _FwdIter>
529void vector<_TypeT, _Allocator>::
530_C_insert_range (iterator __it, _FwdIter __first, _FwdIter __last,
531 forward_iterator_tag)
532{
533 _RWSTD_ASSERT_RANGE (__it, end ());
534 _RWSTD_ASSERT_RANGE (__first, __last);
535
536 // 23.2.4.2, p5: calls to insert() must not reallocate storage
537 // unless the new size of the container would exceed its capacity
538
539 // compute the sizes of the ranges of elements to be copied
540 const size_type __size1 = _DISTANCE (this->begin (), __it, size_type);
541 const size_type __size2 = _DISTANCE (__first, __last, size_type);
542
543 if (!__size2)
544 return;
545
546#ifndef _RWSTD_NO_EXT_VECTOR_INSERT_IN_PLACE
547 const bool __insert_in_place =
548 this->size () + __size2 <= this->capacity ();
549#else // if defined (_RWSTD_NO_EXT_VECTOR_INSERT_IN_PLACE)
550 const bool __insert_in_place = false;
551#endif // _RWSTD_NO_EXT_VECTOR_INSERT_IN_PLACE
552
553 if (__insert_in_place) {
554
555 // compute the beginning an end of the range of elements
556 // in the sequence controlled by *this that need to be moved
557 // (copy contructed past the end of the end of the sequence
558 // or assigned over existing elements)
559 const pointer __movbeg = this->_C_alloc._C_begin + __size1;
560 const pointer __movend = __movbeg + __size2;
561
562 _RWSTD_ASSERT (this->_C_make_iter (__movbeg) == __it);
563
564 const pointer __end = this->_C_alloc._C_end;
565
566 if (__movend <= __end) {
567 // compute the beginning of the range of elements whose copies
568 // will be copy-constructed in the uninitialized space just past
569 // the current end of the sequence
570 const pointer __ucpbeg = __end - __size2;
571
572 // construct copies of elements that will be moved beyond
573 // the current end of the sequence controlled by *this
574 for (pointer __p = __ucpbeg; !(__p == __end); ++__p)
575 this->_C_push_back (*__p);
576
577 // over the range of elements moved above
578 for (pointer __q = __end; __movend < __q; ) {
579 --__q;
580 *__q = *(__q - __size2);
581 }
582 }
583 else {
584 // compute the length of the initial subsequence of the range
585 // of elements being inserted that overlaps the end of the
586 // sequence being inserted into
587 const size_type __size2a = this->size () - __size1;
588 _FwdIter __mid = __first;
589 _STD::advance (__mid, __size2a);
590
591 // construct copies of the trailing subsequence of the range
592 // of elements being inserted, as if by a call to
593 // std::uninitialized_copy (__mid, __last, _C_alloc._C_end);
594
595 for (_FwdIter __m = __mid ; !(__m == __last); ++__m)
596 this->_C_push_back (*__m);
597
598 // construct copies of the range of elements [pos, end)
599 // past the end of the range of elements inserted above,
600 // as if by a call to
601 // std::uninitialized_copy (__movbeg, __end, _C_alloc._C_end);
602
603 for (pointer __p = __movbeg; !(__p == __end); ++__p)
604 this->_C_push_back (*__p);
605
606 __last = __mid;
607 }
608
609 _STD::copy (__first, __last, __movbeg);
610 }
611 else {
612 // 23.2.4.3, p1: If an exception is thrown other than by the copy
613 // constructor or assignment operator of T there are no effects.
614
615 // create a temporary vector and reserve sufficient space
616 vector<value_type, allocator_type> __tmp (this->get_allocator ());
617
618 __tmp.reserve (this->size () + __size2);
619
620 // avoid using the name __i or __it below so as not to trigger
621 // a (bogus) gcc 2.95.2 -Wshadow warning: declaration of `__i'
622 // shadows previous local
623 iterator __ix;
624
625 // copy the initial subsequence of *this, [begin, it), into
626 // the temporary one element at a time, as if by calling
627 // std::unitialized_copy(), growing the temporary at each
628 // iteration so that an exception thrown by the copy ctor
629 // will cause the destruction of all already constructed
630 // elements (by invoking the temporary's dtor)
631 for (__ix = this->begin (); __ix != __it; ++__ix) {
632 __tmp._C_push_back (*__ix);
633 }
634
635 // append the sequence [first, last) to the temporary,
636 // carefully increasing the size of tmp before performing
637 // any operations on `first' and `last' in case they throw
638 for (; !(__first == __last); ++__first) {
639 __tmp._C_push_back (*__first);
640 }
641
642 // copy the remaining elements from *this
643 for ( ; __ix != this->end (); ++__ix) {
644 __tmp._C_push_back (*__ix);
645 }
646
647 // swap *this with the temporary, having its dtor clean up
648 this->swap (__tmp);
649 }
650}
651
652
654#ifndef _RWSTD_NO_VECTOR_BOOL
655
656#ifndef _RWSTD_NO_BOOL
657
658// The body of this function is duplicated in src/vecbool.cpp and
659// further down in this file as well.
660#if !defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
661 template <class _Allocator>
662 template<class _InputIter>
663 void vector<bool, _Allocator >::insert
664#else
665 template<class _InputIter>
666 void vector<bool, allocator<bool> >::insert
667#endif // _RWSTD_NO_CLASS_PARTIAL_SPEC
668 (iterator __it, _InputIter __first, _InputIter __last)
669
670 {
671 if (__first == __last) return;
672 size_type __n = _DISTANCE (__first, __last, size_type);
673 if (capacity() - size() >= __n)
674 {
675 copy_backward(__it, end(), _C_end + __n);
676 copy(__first, __last, __it);
677 _C_end += __n;
678 }
679 else
680 {
681 size_type __len = size() + (max)(size(), __n);
682
683 unsigned int* __q = _C_bit_alloc(__len);
684 iterator __i = copy(begin(), __it, iterator(__q, 0));
685 __i = copy(__first, __last, __i);
686 _C_end = copy(__it, end(), __i);
687 _C_value_alloc_type (*this).
688 deallocate((pointer)_C_begin._C_p,_C_bufend - _C_begin._C_p);
689 _C_bufend = __q + (__len + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
690 _C_begin = iterator(__q, 0);
691 }
692 }
693
694#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
695
696// Duplicates of the following functions exist in src/stl/vecbool.cpp.
697// Which set is used depends on the availability of partial specialization.
698
699 template <class _Allocator>
700 void vector<bool,_Allocator >::flip ()
701 {
702 for (iterator __i = begin(); !(__i == end()); __i++)
703 *__i = !(*__i);
704 }
705
706 template <class _Allocator>
707 void vector<bool,_Allocator >::swap (reference __x, reference __y)
708 {
709 bool __tmp = __x; __x = __y; __y = __tmp;
710 }
711
712
713template <class _Allocator>
714void vector<bool,_Allocator >::
715_C_insert (iterator __it, bool __x)
716{
717 _RWSTD_ASSERT_RANGE (begin (), __it);
718
719 if (size () < capacity ()) {
720
721 const iterator __end = _C_end;
722
723 // move elements in the range [it, end) before the insert
724 // one slot toward the end
725 // i.e., copy [it, end) over [end - (end - it), end)
726 // or, given N = distance(it, end) before the insert,
727 // copy [it, end) over [end - N, end)
728 _STD::copy_backward (__it, __end, ++_C_end);
729
730 // overwrite the element at the given position
731 *__it = __x;
732 }
733 else
734 {
735 size_type __len = size() ? 2 * size() : _RWSTD_WORD_BIT;
736 unsigned int* __q = _C_bit_alloc(__len);
737 iterator __i = _C_copy(begin(), __it, iterator(__q, 0));
738 *__i++ = __x;
739 _C_end = _C_copy(__it, end(), __i);
740 _C_value_alloc_type (*this).
741 deallocate((pointer)_C_begin._C_p,_C_bufend - _C_begin._C_p);
742 _C_bufend = __q + (__len + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
743 _C_begin = iterator(__q, 0);
744 }
745}
746
747
748 template <class _Allocator>
749 void vector<bool,_Allocator >::insert (iterator __it, size_type __n,
750 const bool& __x)
751 {
752 if (__n == 0) return;
753 if (capacity() - size() >= __n)
754 {
755 _C_copy_backward(__it, end(), _C_end + __n);
756 _C_fill(__it, __it + __n, __x);
757 _C_end += __n;
758 }
759 else
760 {
761 size_type __len = size() + (max)(size(), __n);
762 unsigned int* __q = _C_bit_alloc(__len);
763 iterator __i = _C_copy(begin(), __it, iterator(__q, 0));
764 _C_fill_n(__i, __n, __x);
765 _C_end = _C_copy(__it, end(), __i + __n);
766 _C_value_alloc_type (*this).
767 deallocate((pointer)_C_begin._C_p,_C_bufend - _C_begin._C_p);
768 _C_bufend = __q + (__len + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
769 _C_begin = iterator(__q, 0);
770 }
771 }
772
773
774 template <class _Allocator>
775 void vector<bool,_Allocator >::resize (size_type __new_size, bool __c)
776 {
777 if (__new_size > size())
778 insert(end(), __new_size - size(), __c);
779 else if (__new_size < size())
780 erase(begin() + __new_size, end());
781 }
782
783#endif // _RWSTD_NO_CLASS_PARTIAL_SPEC
784
785#endif // _RWSTD_NO_BOOL
786
787#endif // _RWSTD_NO_VECTOR_BOOL
788
789} // namespace std
const int end
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_NEW_CAPACITY(ignore, what, from)
Definition _defs.h:462
#define _RWSTD_ASSERT(ignore)
Definition _defs.h:1108
#define _DISTANCE(first, last, ignore)
Definition _defs.h:1225
#define _RWSTD_ASSERT_RANGE(ign1, ign2)
Definition _defs.h:1247
Definition json.h:5363
#define max(a, b)