Merge with trank @ 137446
[official-gcc.git] / libstdc++-v3 / include / bits / vector.tcc
blob04f76ca2c2c73ea2d7c6bdbd5f91c7e8fa4b0f4e
1 // Vector implementation (out of line) -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
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,
20 // USA.
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.
32  *
33  * Copyright (c) 1994
34  * Hewlett-Packard Company
35  *
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.
43  *
44  *
45  * Copyright (c) 1996
46  * Silicon Graphics Computer Systems, Inc.
47  *
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.
55  */
57 /** @file vector.tcc
58  *  This is an internal header file, included by other library headers.
59  *  You should not attempt to use it directly.
60  */
62 #ifndef _VECTOR_TCC
63 #define _VECTOR_TCC 1
65 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
67   template<typename _Tp, typename _Alloc>
68     void
69     vector<_Tp, _Alloc>::
70     reserve(size_type __n)
71     {
72       if (__n > this->max_size())
73         __throw_length_error(__N("vector::reserve"));
74       if (this->capacity() < __n)
75         {
76           const size_type __old_size = size();
77           pointer __tmp = _M_allocate_and_copy(__n,
78                  _GLIBCXX_MAKE_MOVE_ITERATOR(this->_M_impl._M_start),
79                  _GLIBCXX_MAKE_MOVE_ITERATOR(this->_M_impl._M_finish));
80           std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
81                         _M_get_Tp_allocator());
82           _M_deallocate(this->_M_impl._M_start,
83                         this->_M_impl._M_end_of_storage
84                         - this->_M_impl._M_start);
85           this->_M_impl._M_start = __tmp;
86           this->_M_impl._M_finish = __tmp + __old_size;
87           this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
88         }
89     }
91 #ifdef __GXX_EXPERIMENTAL_CXX0X__
92   template<typename _Tp, typename _Alloc>
93     template<typename... _Args>
94       void
95       vector<_Tp, _Alloc>::
96       emplace_back(_Args&&... __args)
97       {
98         if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
99           {
100             this->_M_impl.construct(this->_M_impl._M_finish,
101                                     std::forward<_Args>(__args)...);
102             ++this->_M_impl._M_finish;
103           }
104         else
105           _M_insert_aux(end(), std::forward<_Args>(__args)...);
106       }
107 #endif
109   template<typename _Tp, typename _Alloc>
110     typename vector<_Tp, _Alloc>::iterator
111     vector<_Tp, _Alloc>::
112     insert(iterator __position, const value_type& __x)
113     {
114       const size_type __n = __position - begin();
115       if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
116           && __position == end())
117         {
118           this->_M_impl.construct(this->_M_impl._M_finish, __x);
119           ++this->_M_impl._M_finish;
120         }
121       else
122         {
123 #ifdef __GXX_EXPERIMENTAL_CXX0X__
124           if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
125             {
126               _Tp __x_copy = __x;
127               _M_insert_aux(__position, std::move(__x_copy));
128             }
129           else
130 #endif
131             _M_insert_aux(__position, __x);
132         }
133       return iterator(this->_M_impl._M_start + __n);
134     }
136   template<typename _Tp, typename _Alloc>
137     typename vector<_Tp, _Alloc>::iterator
138     vector<_Tp, _Alloc>::
139     erase(iterator __position)
140     {
141       if (__position + 1 != end())
142         _GLIBCXX_MOVE3(__position + 1, end(), __position);
143       --this->_M_impl._M_finish;
144       this->_M_impl.destroy(this->_M_impl._M_finish);
145       return __position;
146     }
148   template<typename _Tp, typename _Alloc>
149     typename vector<_Tp, _Alloc>::iterator
150     vector<_Tp, _Alloc>::
151     erase(iterator __first, iterator __last)
152     {
153       if (__last != end())
154         _GLIBCXX_MOVE3(__last, end(), __first);
155       _M_erase_at_end(__first.base() + (end() - __last));
156       return __first;
157     }
159   template<typename _Tp, typename _Alloc>
160     vector<_Tp, _Alloc>&
161     vector<_Tp, _Alloc>::
162     operator=(const vector<_Tp, _Alloc>& __x)
163     {
164       if (&__x != this)
165         {
166           const size_type __xlen = __x.size();
167           if (__xlen > capacity())
168             {
169               pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(),
170                                                    __x.end());
171               std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
172                             _M_get_Tp_allocator());
173               _M_deallocate(this->_M_impl._M_start,
174                             this->_M_impl._M_end_of_storage
175                             - this->_M_impl._M_start);
176               this->_M_impl._M_start = __tmp;
177               this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
178             }
179           else if (size() >= __xlen)
180             {
181               std::_Destroy(std::copy(__x.begin(), __x.end(), begin()),
182                             end(), _M_get_Tp_allocator());
183             }
184           else
185             {
186               std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(),
187                         this->_M_impl._M_start);
188               std::__uninitialized_copy_a(__x._M_impl._M_start + size(),
189                                           __x._M_impl._M_finish,
190                                           this->_M_impl._M_finish,
191                                           _M_get_Tp_allocator());
192             }
193           this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
194         }
195       return *this;
196     }
198   template<typename _Tp, typename _Alloc>
199     void
200     vector<_Tp, _Alloc>::
201     _M_fill_assign(size_t __n, const value_type& __val)
202     {
203       if (__n > capacity())
204         {
205           vector __tmp(__n, __val, _M_get_Tp_allocator());
206           __tmp.swap(*this);
207         }
208       else if (__n > size())
209         {
210           std::fill(begin(), end(), __val);
211           std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
212                                         __n - size(), __val,
213                                         _M_get_Tp_allocator());
214           this->_M_impl._M_finish += __n - size();
215         }
216       else
217         _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val));
218     }
220   template<typename _Tp, typename _Alloc>
221     template<typename _InputIterator>
222       void
223       vector<_Tp, _Alloc>::
224       _M_assign_aux(_InputIterator __first, _InputIterator __last,
225                     std::input_iterator_tag)
226       {
227         pointer __cur(this->_M_impl._M_start);
228         for (; __first != __last && __cur != this->_M_impl._M_finish;
229              ++__cur, ++__first)
230           *__cur = *__first;
231         if (__first == __last)
232           _M_erase_at_end(__cur);
233         else
234           insert(end(), __first, __last);
235       }
237   template<typename _Tp, typename _Alloc>
238     template<typename _ForwardIterator>
239       void
240       vector<_Tp, _Alloc>::
241       _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
242                     std::forward_iterator_tag)
243       {
244         const size_type __len = std::distance(__first, __last);
246         if (__len > capacity())
247           {
248             pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
249             std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
250                           _M_get_Tp_allocator());
251             _M_deallocate(this->_M_impl._M_start,
252                           this->_M_impl._M_end_of_storage
253                           - this->_M_impl._M_start);
254             this->_M_impl._M_start = __tmp;
255             this->_M_impl._M_finish = this->_M_impl._M_start + __len;
256             this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
257           }
258         else if (size() >= __len)
259           _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
260         else
261           {
262             _ForwardIterator __mid = __first;
263             std::advance(__mid, size());
264             std::copy(__first, __mid, this->_M_impl._M_start);
265             this->_M_impl._M_finish =
266               std::__uninitialized_copy_a(__mid, __last,
267                                           this->_M_impl._M_finish,
268                                           _M_get_Tp_allocator());
269           }
270       }
272 #ifdef __GXX_EXPERIMENTAL_CXX0X__
273   template<typename _Tp, typename _Alloc>
274     template<typename... _Args>
275       typename vector<_Tp, _Alloc>::iterator
276       vector<_Tp, _Alloc>::
277       emplace(iterator __position, _Args&&... __args)
278       {
279         const size_type __n = __position - begin();
280         if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
281             && __position == end())
282           {
283             this->_M_impl.construct(this->_M_impl._M_finish,
284                                     std::forward<_Args>(__args)...);
285             ++this->_M_impl._M_finish;
286           }
287         else
288           _M_insert_aux(__position, std::forward<_Args>(__args)...);
289         return iterator(this->_M_impl._M_start + __n);
290       }
292   template<typename _Tp, typename _Alloc>
293     template<typename... _Args>
294       void
295       vector<_Tp, _Alloc>::
296       _M_insert_aux(iterator __position, _Args&&... __args)
297 #else
298   template<typename _Tp, typename _Alloc>
299     void
300     vector<_Tp, _Alloc>::
301     _M_insert_aux(iterator __position, const _Tp& __x)
302 #endif
303     {
304       if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
305         {
306           this->_M_impl.construct(this->_M_impl._M_finish,
307                                   _GLIBCXX_MOVE(*(this->_M_impl._M_finish
308                                                   - 1)));
309           ++this->_M_impl._M_finish;
310 #ifndef __GXX_EXPERIMENTAL_CXX0X__
311           _Tp __x_copy = __x;
312 #endif
313           _GLIBCXX_MOVE_BACKWARD3(__position.base(),
314                                   this->_M_impl._M_finish - 2,
315                                   this->_M_impl._M_finish - 1);
316 #ifndef __GXX_EXPERIMENTAL_CXX0X__
317           *__position = __x_copy;
318 #else
319           *__position = _Tp(std::forward<_Args>(__args)...);
320 #endif
321         }
322       else
323         {
324           const size_type __len =
325             _M_check_len(size_type(1), "vector::_M_insert_aux");
326           const size_type __elems_before = __position - begin();
327           pointer __new_start(this->_M_allocate(__len));
328           pointer __new_finish(__new_start);
329           try
330             {
331               // The order of the three operations is dictated by the C++0x
332               // case, where the moves could alter a new element belonging
333               // to the existing vector.  This is an issue only for callers
334               // taking the element by const lvalue ref (see 23.1/13).
335               this->_M_impl.construct(__new_start + __elems_before,
336 #ifdef __GXX_EXPERIMENTAL_CXX0X__
337                                       std::forward<_Args>(__args)...);
338 #else
339                                       __x);
340 #endif
341               __new_finish = 0;
343               __new_finish =
344                 std::__uninitialized_move_a(this->_M_impl._M_start,
345                                             __position.base(), __new_start,
346                                             _M_get_Tp_allocator());
347               ++__new_finish;
349               __new_finish =
350                 std::__uninitialized_move_a(__position.base(),
351                                             this->_M_impl._M_finish,
352                                             __new_finish,
353                                             _M_get_Tp_allocator());
354             }
355           catch(...)
356             {
357               if (!__new_finish)
358                 this->_M_impl.destroy(__new_start + __elems_before);
359               else
360                 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
361               _M_deallocate(__new_start, __len);
362               __throw_exception_again;
363             }
364           std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
365                         _M_get_Tp_allocator());
366           _M_deallocate(this->_M_impl._M_start,
367                         this->_M_impl._M_end_of_storage
368                         - this->_M_impl._M_start);
369           this->_M_impl._M_start = __new_start;
370           this->_M_impl._M_finish = __new_finish;
371           this->_M_impl._M_end_of_storage = __new_start + __len;
372         }
373     }
375   template<typename _Tp, typename _Alloc>
376     void
377     vector<_Tp, _Alloc>::
378     _M_fill_insert(iterator __position, size_type __n, const value_type& __x)
379     {
380       if (__n != 0)
381         {
382           if (size_type(this->_M_impl._M_end_of_storage
383                         - this->_M_impl._M_finish) >= __n)
384             {
385               value_type __x_copy = __x;
386               const size_type __elems_after = end() - __position;
387               pointer __old_finish(this->_M_impl._M_finish);
388               if (__elems_after > __n)
389                 {
390                   std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
391                                               this->_M_impl._M_finish,
392                                               this->_M_impl._M_finish,
393                                               _M_get_Tp_allocator());
394                   this->_M_impl._M_finish += __n;
395                   _GLIBCXX_MOVE_BACKWARD3(__position.base(),
396                                           __old_finish - __n, __old_finish);
397                   std::fill(__position.base(), __position.base() + __n,
398                             __x_copy);
399                 }
400               else
401                 {
402                   std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
403                                                 __n - __elems_after,
404                                                 __x_copy,
405                                                 _M_get_Tp_allocator());
406                   this->_M_impl._M_finish += __n - __elems_after;
407                   std::__uninitialized_move_a(__position.base(), __old_finish,
408                                               this->_M_impl._M_finish,
409                                               _M_get_Tp_allocator());
410                   this->_M_impl._M_finish += __elems_after;
411                   std::fill(__position.base(), __old_finish, __x_copy);
412                 }
413             }
414           else
415             {
416               const size_type __len =
417                 _M_check_len(__n, "vector::_M_fill_insert");
418               const size_type __elems_before = __position - begin();
419               pointer __new_start(this->_M_allocate(__len));
420               pointer __new_finish(__new_start);
421               try
422                 {
423                   // See _M_insert_aux above.
424                   std::__uninitialized_fill_n_a(__new_start + __elems_before,
425                                                 __n, __x,
426                                                 _M_get_Tp_allocator());
427                   __new_finish = 0;
429                   __new_finish =
430                     std::__uninitialized_move_a(this->_M_impl._M_start,
431                                                 __position.base(),
432                                                 __new_start,
433                                                 _M_get_Tp_allocator());
434                   __new_finish += __n;
436                   __new_finish =
437                     std::__uninitialized_move_a(__position.base(),
438                                                 this->_M_impl._M_finish,
439                                                 __new_finish,
440                                                 _M_get_Tp_allocator());
441                 }
442               catch(...)
443                 {
444                   if (!__new_finish)
445                     std::_Destroy(__new_start + __elems_before,
446                                   __new_start + __elems_before + __n,
447                                   _M_get_Tp_allocator());
448                   else
449                     std::_Destroy(__new_start, __new_finish,
450                                   _M_get_Tp_allocator());
451                   _M_deallocate(__new_start, __len);
452                   __throw_exception_again;
453                 }
454               std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
455                             _M_get_Tp_allocator());
456               _M_deallocate(this->_M_impl._M_start,
457                             this->_M_impl._M_end_of_storage
458                             - this->_M_impl._M_start);
459               this->_M_impl._M_start = __new_start;
460               this->_M_impl._M_finish = __new_finish;
461               this->_M_impl._M_end_of_storage = __new_start + __len;
462             }
463         }
464     }
466   template<typename _Tp, typename _Alloc>
467     template<typename _InputIterator>
468       void
469       vector<_Tp, _Alloc>::
470       _M_range_insert(iterator __pos, _InputIterator __first,
471                       _InputIterator __last, std::input_iterator_tag)
472       {
473         for (; __first != __last; ++__first)
474           {
475             __pos = insert(__pos, *__first);
476             ++__pos;
477           }
478       }
480   template<typename _Tp, typename _Alloc>
481     template<typename _ForwardIterator>
482       void
483       vector<_Tp, _Alloc>::
484       _M_range_insert(iterator __position, _ForwardIterator __first,
485                       _ForwardIterator __last, std::forward_iterator_tag)
486       {
487         if (__first != __last)
488           {
489             const size_type __n = std::distance(__first, __last);
490             if (size_type(this->_M_impl._M_end_of_storage
491                           - this->_M_impl._M_finish) >= __n)
492               {
493                 const size_type __elems_after = end() - __position;
494                 pointer __old_finish(this->_M_impl._M_finish);
495                 if (__elems_after > __n)
496                   {
497                     std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
498                                                 this->_M_impl._M_finish,
499                                                 this->_M_impl._M_finish,
500                                                 _M_get_Tp_allocator());
501                     this->_M_impl._M_finish += __n;
502                     _GLIBCXX_MOVE_BACKWARD3(__position.base(),
503                                             __old_finish - __n, __old_finish);
504                     std::copy(__first, __last, __position);
505                   }
506                 else
507                   {
508                     _ForwardIterator __mid = __first;
509                     std::advance(__mid, __elems_after);
510                     std::__uninitialized_copy_a(__mid, __last,
511                                                 this->_M_impl._M_finish,
512                                                 _M_get_Tp_allocator());
513                     this->_M_impl._M_finish += __n - __elems_after;
514                     std::__uninitialized_move_a(__position.base(),
515                                                 __old_finish,
516                                                 this->_M_impl._M_finish,
517                                                 _M_get_Tp_allocator());
518                     this->_M_impl._M_finish += __elems_after;
519                     std::copy(__first, __mid, __position);
520                   }
521               }
522             else
523               {
524                 const size_type __len =
525                   _M_check_len(__n, "vector::_M_range_insert");
526                 pointer __new_start(this->_M_allocate(__len));
527                 pointer __new_finish(__new_start);
528                 try
529                   {
530                     __new_finish =
531                       std::__uninitialized_move_a(this->_M_impl._M_start,
532                                                   __position.base(),
533                                                   __new_start,
534                                                   _M_get_Tp_allocator());
535                     __new_finish =
536                       std::__uninitialized_copy_a(__first, __last,
537                                                   __new_finish,
538                                                   _M_get_Tp_allocator());
539                     __new_finish =
540                       std::__uninitialized_move_a(__position.base(),
541                                                   this->_M_impl._M_finish,
542                                                   __new_finish,
543                                                   _M_get_Tp_allocator());
544                   }
545                 catch(...)
546                   {
547                     std::_Destroy(__new_start, __new_finish,
548                                   _M_get_Tp_allocator());
549                     _M_deallocate(__new_start, __len);
550                     __throw_exception_again;
551                   }
552                 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
553                               _M_get_Tp_allocator());
554                 _M_deallocate(this->_M_impl._M_start,
555                               this->_M_impl._M_end_of_storage
556                               - this->_M_impl._M_start);
557                 this->_M_impl._M_start = __new_start;
558                 this->_M_impl._M_finish = __new_finish;
559                 this->_M_impl._M_end_of_storage = __new_start + __len;
560               }
561           }
562       }
565   // vector<bool>
567   template<typename _Alloc>
568     void
569     vector<bool, _Alloc>::
570     reserve(size_type __n)
571     {
572       if (__n > this->max_size())
573         __throw_length_error(__N("vector::reserve"));
574       if (this->capacity() < __n)
575         {
576           _Bit_type* __q = this->_M_allocate(__n);
577           this->_M_impl._M_finish = _M_copy_aligned(begin(), end(),
578                                                     iterator(__q, 0));
579           this->_M_deallocate();
580           this->_M_impl._M_start = iterator(__q, 0);
581           this->_M_impl._M_end_of_storage = (__q + (__n + int(_S_word_bit) - 1)
582                                              / int(_S_word_bit));
583         }
584     }
586   template<typename _Alloc>
587     void
588     vector<bool, _Alloc>::
589     _M_fill_insert(iterator __position, size_type __n, bool __x)
590     {
591       if (__n == 0)
592         return;
593       if (capacity() - size() >= __n)
594         {
595           std::copy_backward(__position, end(),
596                              this->_M_impl._M_finish + difference_type(__n));
597           std::fill(__position, __position + difference_type(__n), __x);
598           this->_M_impl._M_finish += difference_type(__n);
599         }
600       else
601         {
602           const size_type __len = 
603             _M_check_len(__n, "vector<bool>::_M_fill_insert");
604           _Bit_type * __q = this->_M_allocate(__len);
605           iterator __i = _M_copy_aligned(begin(), __position,
606                                          iterator(__q, 0));
607           std::fill(__i, __i + difference_type(__n), __x);
608           this->_M_impl._M_finish = std::copy(__position, end(),
609                                               __i + difference_type(__n));
610           this->_M_deallocate();
611           this->_M_impl._M_end_of_storage = (__q + ((__len
612                                                      + int(_S_word_bit) - 1)
613                                                     / int(_S_word_bit)));
614           this->_M_impl._M_start = iterator(__q, 0);
615         }
616     }
618   template<typename _Alloc>
619     template<typename _ForwardIterator>
620       void
621       vector<bool, _Alloc>::
622       _M_insert_range(iterator __position, _ForwardIterator __first, 
623                       _ForwardIterator __last, std::forward_iterator_tag)
624       {
625         if (__first != __last)
626           {
627             size_type __n = std::distance(__first, __last);
628             if (capacity() - size() >= __n)
629               {
630                 std::copy_backward(__position, end(),
631                                    this->_M_impl._M_finish
632                                    + difference_type(__n));
633                 std::copy(__first, __last, __position);
634                 this->_M_impl._M_finish += difference_type(__n);
635               }
636             else
637               {
638                 const size_type __len =
639                   _M_check_len(__n, "vector<bool>::_M_insert_range");
640                 _Bit_type * __q = this->_M_allocate(__len);
641                 iterator __i = _M_copy_aligned(begin(), __position,
642                                                iterator(__q, 0));
643                 __i = std::copy(__first, __last, __i);
644                 this->_M_impl._M_finish = std::copy(__position, end(), __i);
645                 this->_M_deallocate();
646                 this->_M_impl._M_end_of_storage = (__q
647                                                    + ((__len
648                                                        + int(_S_word_bit) - 1)
649                                                       / int(_S_word_bit)));
650                 this->_M_impl._M_start = iterator(__q, 0);
651               }
652           }
653       }
655   template<typename _Alloc>
656     void
657     vector<bool, _Alloc>::
658     _M_insert_aux(iterator __position, bool __x)
659     {
660       if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
661         {
662           std::copy_backward(__position, this->_M_impl._M_finish, 
663                              this->_M_impl._M_finish + 1);
664           *__position = __x;
665           ++this->_M_impl._M_finish;
666         }
667       else
668         {
669           const size_type __len =
670             _M_check_len(size_type(1), "vector<bool>::_M_insert_aux");
671           _Bit_type * __q = this->_M_allocate(__len);
672           iterator __i = _M_copy_aligned(begin(), __position,
673                                          iterator(__q, 0));
674           *__i++ = __x;
675           this->_M_impl._M_finish = std::copy(__position, end(), __i);
676           this->_M_deallocate();
677           this->_M_impl._M_end_of_storage = (__q + ((__len
678                                                      + int(_S_word_bit) - 1)
679                                                     / int(_S_word_bit)));
680           this->_M_impl._M_start = iterator(__q, 0);
681         }
682     }
684 _GLIBCXX_END_NESTED_NAMESPACE
686 #endif /* _VECTOR_TCC */