libstdc++
vector.tcc
Go to the documentation of this file.
00001 // Vector implementation (out of line) -*- C++ -*-
00002 
00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
00004 // 2011 Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 3, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 /*
00027  *
00028  * Copyright (c) 1994
00029  * Hewlett-Packard Company
00030  *
00031  * Permission to use, copy, modify, distribute and sell this software
00032  * and its documentation for any purpose is hereby granted without fee,
00033  * provided that the above copyright notice appear in all copies and
00034  * that both that copyright notice and this permission notice appear
00035  * in supporting documentation.  Hewlett-Packard Company makes no
00036  * representations about the suitability of this software for any
00037  * purpose.  It is provided "as is" without express or implied warranty.
00038  *
00039  *
00040  * Copyright (c) 1996
00041  * Silicon Graphics Computer Systems, Inc.
00042  *
00043  * Permission to use, copy, modify, distribute and sell this software
00044  * and its documentation for any purpose is hereby granted without fee,
00045  * provided that the above copyright notice appear in all copies and
00046  * that both that copyright notice and this permission notice appear
00047  * in supporting documentation.  Silicon Graphics makes no
00048  * representations about the suitability of this  software for any
00049  * purpose.  It is provided "as is" without express or implied warranty.
00050  */
00051 
00052 /** @file bits/vector.tcc
00053  *  This is an internal header file, included by other library headers.
00054  *  Do not attempt to use it directly. @headername{vector}
00055  */
00056 
00057 #ifndef _VECTOR_TCC
00058 #define _VECTOR_TCC 1
00059 
00060 namespace std _GLIBCXX_VISIBILITY(default)
00061 {
00062 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
00063 
00064   template<typename _Tp, typename _Alloc>
00065     void
00066     vector<_Tp, _Alloc>::
00067     reserve(size_type __n)
00068     {
00069       if (__n > this->max_size())
00070     __throw_length_error(__N("vector::reserve"));
00071       if (this->capacity() < __n)
00072     {
00073       const size_type __old_size = size();
00074       pointer __tmp = _M_allocate_and_copy(__n,
00075          _GLIBCXX_MAKE_MOVE_ITERATOR(this->_M_impl._M_start),
00076          _GLIBCXX_MAKE_MOVE_ITERATOR(this->_M_impl._M_finish));
00077       std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
00078             _M_get_Tp_allocator());
00079       _M_deallocate(this->_M_impl._M_start,
00080             this->_M_impl._M_end_of_storage
00081             - this->_M_impl._M_start);
00082       this->_M_impl._M_start = __tmp;
00083       this->_M_impl._M_finish = __tmp + __old_size;
00084       this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
00085     }
00086     }
00087 
00088 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00089   template<typename _Tp, typename _Alloc>
00090     template<typename... _Args>
00091       void
00092       vector<_Tp, _Alloc>::
00093       emplace_back(_Args&&... __args)
00094       {
00095     if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
00096       {
00097         this->_M_impl.construct(this->_M_impl._M_finish,
00098                     std::forward<_Args>(__args)...);
00099         ++this->_M_impl._M_finish;
00100       }
00101     else
00102       _M_insert_aux(end(), std::forward<_Args>(__args)...);
00103       }
00104 #endif
00105 
00106   template<typename _Tp, typename _Alloc>
00107     typename vector<_Tp, _Alloc>::iterator
00108     vector<_Tp, _Alloc>::
00109     insert(iterator __position, const value_type& __x)
00110     {
00111       const size_type __n = __position - begin();
00112       if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
00113       && __position == end())
00114     {
00115       this->_M_impl.construct(this->_M_impl._M_finish, __x);
00116       ++this->_M_impl._M_finish;
00117     }
00118       else
00119     {
00120 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00121       if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
00122         {
00123           _Tp __x_copy = __x;
00124           _M_insert_aux(__position, std::move(__x_copy));
00125         }
00126       else
00127 #endif
00128         _M_insert_aux(__position, __x);
00129     }
00130       return iterator(this->_M_impl._M_start + __n);
00131     }
00132 
00133   template<typename _Tp, typename _Alloc>
00134     typename vector<_Tp, _Alloc>::iterator
00135     vector<_Tp, _Alloc>::
00136     erase(iterator __position)
00137     {
00138       if (__position + 1 != end())
00139     _GLIBCXX_MOVE3(__position + 1, end(), __position);
00140       --this->_M_impl._M_finish;
00141       this->_M_impl.destroy(this->_M_impl._M_finish);
00142       return __position;
00143     }
00144 
00145   template<typename _Tp, typename _Alloc>
00146     typename vector<_Tp, _Alloc>::iterator
00147     vector<_Tp, _Alloc>::
00148     erase(iterator __first, iterator __last)
00149     {
00150       if (__first != __last)
00151     {
00152       if (__last != end())
00153         _GLIBCXX_MOVE3(__last, end(), __first);
00154       _M_erase_at_end(__first.base() + (end() - __last));
00155     }
00156       return __first;
00157     }
00158 
00159   template<typename _Tp, typename _Alloc>
00160     vector<_Tp, _Alloc>&
00161     vector<_Tp, _Alloc>::
00162     operator=(const vector<_Tp, _Alloc>& __x)
00163     {
00164       if (&__x != this)
00165     {
00166       const size_type __xlen = __x.size();
00167       if (__xlen > capacity())
00168         {
00169           pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(),
00170                            __x.end());
00171           std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
00172                 _M_get_Tp_allocator());
00173           _M_deallocate(this->_M_impl._M_start,
00174                 this->_M_impl._M_end_of_storage
00175                 - this->_M_impl._M_start);
00176           this->_M_impl._M_start = __tmp;
00177           this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
00178         }
00179       else if (size() >= __xlen)
00180         {
00181           std::_Destroy(std::copy(__x.begin(), __x.end(), begin()),
00182                 end(), _M_get_Tp_allocator());
00183         }
00184       else
00185         {
00186           std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(),
00187             this->_M_impl._M_start);
00188           std::__uninitialized_copy_a(__x._M_impl._M_start + size(),
00189                       __x._M_impl._M_finish,
00190                       this->_M_impl._M_finish,
00191                       _M_get_Tp_allocator());
00192         }
00193       this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
00194     }
00195       return *this;
00196     }
00197 
00198   template<typename _Tp, typename _Alloc>
00199     void
00200     vector<_Tp, _Alloc>::
00201     _M_fill_assign(size_t __n, const value_type& __val)
00202     {
00203       if (__n > capacity())
00204     {
00205       vector __tmp(__n, __val, _M_get_Tp_allocator());
00206       __tmp.swap(*this);
00207     }
00208       else if (__n > size())
00209     {
00210       std::fill(begin(), end(), __val);
00211       std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
00212                     __n - size(), __val,
00213                     _M_get_Tp_allocator());
00214       this->_M_impl._M_finish += __n - size();
00215     }
00216       else
00217         _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val));
00218     }
00219 
00220   template<typename _Tp, typename _Alloc>
00221     template<typename _InputIterator>
00222       void
00223       vector<_Tp, _Alloc>::
00224       _M_assign_aux(_InputIterator __first, _InputIterator __last,
00225             std::input_iterator_tag)
00226       {
00227     pointer __cur(this->_M_impl._M_start);
00228     for (; __first != __last && __cur != this->_M_impl._M_finish;
00229          ++__cur, ++__first)
00230       *__cur = *__first;
00231     if (__first == __last)
00232       _M_erase_at_end(__cur);
00233     else
00234       insert(end(), __first, __last);
00235       }
00236 
00237   template<typename _Tp, typename _Alloc>
00238     template<typename _ForwardIterator>
00239       void
00240       vector<_Tp, _Alloc>::
00241       _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
00242             std::forward_iterator_tag)
00243       {
00244     const size_type __len = std::distance(__first, __last);
00245 
00246     if (__len > capacity())
00247       {
00248         pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
00249         std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
00250               _M_get_Tp_allocator());
00251         _M_deallocate(this->_M_impl._M_start,
00252               this->_M_impl._M_end_of_storage
00253               - this->_M_impl._M_start);
00254         this->_M_impl._M_start = __tmp;
00255         this->_M_impl._M_finish = this->_M_impl._M_start + __len;
00256         this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
00257       }
00258     else if (size() >= __len)
00259       _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
00260     else
00261       {
00262         _ForwardIterator __mid = __first;
00263         std::advance(__mid, size());
00264         std::copy(__first, __mid, this->_M_impl._M_start);
00265         this->_M_impl._M_finish =
00266           std::__uninitialized_copy_a(__mid, __last,
00267                       this->_M_impl._M_finish,
00268                       _M_get_Tp_allocator());
00269       }
00270       }
00271 
00272 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00273   template<typename _Tp, typename _Alloc>
00274     template<typename... _Args>
00275       typename vector<_Tp, _Alloc>::iterator
00276       vector<_Tp, _Alloc>::
00277       emplace(iterator __position, _Args&&... __args)
00278       {
00279     const size_type __n = __position - begin();
00280     if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
00281         && __position == end())
00282       {
00283         this->_M_impl.construct(this->_M_impl._M_finish,
00284                     std::forward<_Args>(__args)...);
00285         ++this->_M_impl._M_finish;
00286       }
00287     else
00288       _M_insert_aux(__position, std::forward<_Args>(__args)...);
00289     return iterator(this->_M_impl._M_start + __n);
00290       }
00291 
00292   template<typename _Tp, typename _Alloc>
00293     template<typename... _Args>
00294       void
00295       vector<_Tp, _Alloc>::
00296       _M_insert_aux(iterator __position, _Args&&... __args)
00297 #else
00298   template<typename _Tp, typename _Alloc>
00299     void
00300     vector<_Tp, _Alloc>::
00301     _M_insert_aux(iterator __position, const _Tp& __x)
00302 #endif
00303     {
00304       if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
00305     {
00306       this->_M_impl.construct(this->_M_impl._M_finish,
00307                   _GLIBCXX_MOVE(*(this->_M_impl._M_finish
00308                           - 1)));
00309       ++this->_M_impl._M_finish;
00310 #ifndef __GXX_EXPERIMENTAL_CXX0X__
00311       _Tp __x_copy = __x;
00312 #endif
00313       _GLIBCXX_MOVE_BACKWARD3(__position.base(),
00314                   this->_M_impl._M_finish - 2,
00315                   this->_M_impl._M_finish - 1);
00316 #ifndef __GXX_EXPERIMENTAL_CXX0X__
00317       *__position = __x_copy;
00318 #else
00319       *__position = _Tp(std::forward<_Args>(__args)...);
00320 #endif
00321     }
00322       else
00323     {
00324       const size_type __len =
00325         _M_check_len(size_type(1), "vector::_M_insert_aux");
00326       const size_type __elems_before = __position - begin();
00327       pointer __new_start(this->_M_allocate(__len));
00328       pointer __new_finish(__new_start);
00329       __try
00330         {
00331           // The order of the three operations is dictated by the C++0x
00332           // case, where the moves could alter a new element belonging
00333           // to the existing vector.  This is an issue only for callers
00334           // taking the element by const lvalue ref (see 23.1/13).
00335           this->_M_impl.construct(__new_start + __elems_before,
00336 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00337                       std::forward<_Args>(__args)...);
00338 #else
00339                                   __x);
00340 #endif
00341           __new_finish = 0;
00342 
00343           __new_finish =
00344         std::__uninitialized_move_a(this->_M_impl._M_start,
00345                         __position.base(), __new_start,
00346                         _M_get_Tp_allocator());
00347           ++__new_finish;
00348 
00349           __new_finish =
00350         std::__uninitialized_move_a(__position.base(),
00351                         this->_M_impl._M_finish,
00352                         __new_finish,
00353                         _M_get_Tp_allocator());
00354         }
00355           __catch(...)
00356         {
00357           if (!__new_finish)
00358         this->_M_impl.destroy(__new_start + __elems_before);
00359           else
00360         std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
00361           _M_deallocate(__new_start, __len);
00362           __throw_exception_again;
00363         }
00364       std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
00365             _M_get_Tp_allocator());
00366       _M_deallocate(this->_M_impl._M_start,
00367             this->_M_impl._M_end_of_storage
00368             - this->_M_impl._M_start);
00369       this->_M_impl._M_start = __new_start;
00370       this->_M_impl._M_finish = __new_finish;
00371       this->_M_impl._M_end_of_storage = __new_start + __len;
00372     }
00373     }
00374 
00375   template<typename _Tp, typename _Alloc>
00376     void
00377     vector<_Tp, _Alloc>::
00378     _M_fill_insert(iterator __position, size_type __n, const value_type& __x)
00379     {
00380       if (__n != 0)
00381     {
00382       if (size_type(this->_M_impl._M_end_of_storage
00383             - this->_M_impl._M_finish) >= __n)
00384         {
00385           value_type __x_copy = __x;
00386           const size_type __elems_after = end() - __position;
00387           pointer __old_finish(this->_M_impl._M_finish);
00388           if (__elems_after > __n)
00389         {
00390           std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
00391                           this->_M_impl._M_finish,
00392                           this->_M_impl._M_finish,
00393                           _M_get_Tp_allocator());
00394           this->_M_impl._M_finish += __n;
00395           _GLIBCXX_MOVE_BACKWARD3(__position.base(),
00396                       __old_finish - __n, __old_finish);
00397           std::fill(__position.base(), __position.base() + __n,
00398                 __x_copy);
00399         }
00400           else
00401         {
00402           std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
00403                         __n - __elems_after,
00404                         __x_copy,
00405                         _M_get_Tp_allocator());
00406           this->_M_impl._M_finish += __n - __elems_after;
00407           std::__uninitialized_move_a(__position.base(), __old_finish,
00408                           this->_M_impl._M_finish,
00409                           _M_get_Tp_allocator());
00410           this->_M_impl._M_finish += __elems_after;
00411           std::fill(__position.base(), __old_finish, __x_copy);
00412         }
00413         }
00414       else
00415         {
00416           const size_type __len =
00417         _M_check_len(__n, "vector::_M_fill_insert");
00418           const size_type __elems_before = __position - begin();
00419           pointer __new_start(this->_M_allocate(__len));
00420           pointer __new_finish(__new_start);
00421           __try
00422         {
00423           // See _M_insert_aux above.
00424           std::__uninitialized_fill_n_a(__new_start + __elems_before,
00425                         __n, __x,
00426                         _M_get_Tp_allocator());
00427           __new_finish = 0;
00428 
00429           __new_finish =
00430             std::__uninitialized_move_a(this->_M_impl._M_start,
00431                         __position.base(),
00432                         __new_start,
00433                         _M_get_Tp_allocator());
00434           __new_finish += __n;
00435 
00436           __new_finish =
00437             std::__uninitialized_move_a(__position.base(),
00438                         this->_M_impl._M_finish,
00439                         __new_finish,
00440                         _M_get_Tp_allocator());
00441         }
00442           __catch(...)
00443         {
00444           if (!__new_finish)
00445             std::_Destroy(__new_start + __elems_before,
00446                   __new_start + __elems_before + __n,
00447                   _M_get_Tp_allocator());
00448           else
00449             std::_Destroy(__new_start, __new_finish,
00450                   _M_get_Tp_allocator());
00451           _M_deallocate(__new_start, __len);
00452           __throw_exception_again;
00453         }
00454           std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
00455                 _M_get_Tp_allocator());
00456           _M_deallocate(this->_M_impl._M_start,
00457                 this->_M_impl._M_end_of_storage
00458                 - this->_M_impl._M_start);
00459           this->_M_impl._M_start = __new_start;
00460           this->_M_impl._M_finish = __new_finish;
00461           this->_M_impl._M_end_of_storage = __new_start + __len;
00462         }
00463     }
00464     }
00465 
00466 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00467   template<typename _Tp, typename _Alloc>
00468     void
00469     vector<_Tp, _Alloc>::
00470     _M_default_append(size_type __n)
00471     {
00472       if (__n != 0)
00473     {
00474       if (size_type(this->_M_impl._M_end_of_storage
00475             - this->_M_impl._M_finish) >= __n)
00476         {
00477           std::__uninitialized_default_n_a(this->_M_impl._M_finish,
00478                            __n, _M_get_Tp_allocator());
00479           this->_M_impl._M_finish += __n;
00480         }
00481       else
00482         {
00483           const size_type __len =
00484         _M_check_len(__n, "vector::_M_default_append");
00485           const size_type __old_size = this->size();
00486           pointer __new_start(this->_M_allocate(__len));
00487           pointer __new_finish(__new_start);
00488           __try
00489         {
00490           __new_finish =
00491             std::__uninitialized_move_a(this->_M_impl._M_start,
00492                         this->_M_impl._M_finish,
00493                         __new_start,
00494                         _M_get_Tp_allocator());
00495           std::__uninitialized_default_n_a(__new_finish, __n,
00496                            _M_get_Tp_allocator());
00497           __new_finish += __n;
00498         }
00499           __catch(...)
00500         {
00501           std::_Destroy(__new_start, __new_finish,
00502                 _M_get_Tp_allocator());
00503           _M_deallocate(__new_start, __len);
00504           __throw_exception_again;
00505         }
00506           std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
00507                 _M_get_Tp_allocator());
00508           _M_deallocate(this->_M_impl._M_start,
00509                 this->_M_impl._M_end_of_storage
00510                 - this->_M_impl._M_start);
00511           this->_M_impl._M_start = __new_start;
00512           this->_M_impl._M_finish = __new_finish;
00513           this->_M_impl._M_end_of_storage = __new_start + __len;
00514         }
00515     }
00516     }
00517 #endif
00518 
00519   template<typename _Tp, typename _Alloc>
00520     template<typename _InputIterator>
00521       void
00522       vector<_Tp, _Alloc>::
00523       _M_range_insert(iterator __pos, _InputIterator __first,
00524               _InputIterator __last, std::input_iterator_tag)
00525       {
00526     for (; __first != __last; ++__first)
00527       {
00528         __pos = insert(__pos, *__first);
00529         ++__pos;
00530       }
00531       }
00532 
00533   template<typename _Tp, typename _Alloc>
00534     template<typename _ForwardIterator>
00535       void
00536       vector<_Tp, _Alloc>::
00537       _M_range_insert(iterator __position, _ForwardIterator __first,
00538               _ForwardIterator __last, std::forward_iterator_tag)
00539       {
00540     if (__first != __last)
00541       {
00542         const size_type __n = std::distance(__first, __last);
00543         if (size_type(this->_M_impl._M_end_of_storage
00544               - this->_M_impl._M_finish) >= __n)
00545           {
00546         const size_type __elems_after = end() - __position;
00547         pointer __old_finish(this->_M_impl._M_finish);
00548         if (__elems_after > __n)
00549           {
00550             std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
00551                         this->_M_impl._M_finish,
00552                         this->_M_impl._M_finish,
00553                         _M_get_Tp_allocator());
00554             this->_M_impl._M_finish += __n;
00555             _GLIBCXX_MOVE_BACKWARD3(__position.base(),
00556                         __old_finish - __n, __old_finish);
00557             std::copy(__first, __last, __position);
00558           }
00559         else
00560           {
00561             _ForwardIterator __mid = __first;
00562             std::advance(__mid, __elems_after);
00563             std::__uninitialized_copy_a(__mid, __last,
00564                         this->_M_impl._M_finish,
00565                         _M_get_Tp_allocator());
00566             this->_M_impl._M_finish += __n - __elems_after;
00567             std::__uninitialized_move_a(__position.base(),
00568                         __old_finish,
00569                         this->_M_impl._M_finish,
00570                         _M_get_Tp_allocator());
00571             this->_M_impl._M_finish += __elems_after;
00572             std::copy(__first, __mid, __position);
00573           }
00574           }
00575         else
00576           {
00577         const size_type __len =
00578           _M_check_len(__n, "vector::_M_range_insert");
00579         pointer __new_start(this->_M_allocate(__len));
00580         pointer __new_finish(__new_start);
00581         __try
00582           {
00583             __new_finish =
00584               std::__uninitialized_move_a(this->_M_impl._M_start,
00585                           __position.base(),
00586                           __new_start,
00587                           _M_get_Tp_allocator());
00588             __new_finish =
00589               std::__uninitialized_copy_a(__first, __last,
00590                           __new_finish,
00591                           _M_get_Tp_allocator());
00592             __new_finish =
00593               std::__uninitialized_move_a(__position.base(),
00594                           this->_M_impl._M_finish,
00595                           __new_finish,
00596                           _M_get_Tp_allocator());
00597           }
00598         __catch(...)
00599           {
00600             std::_Destroy(__new_start, __new_finish,
00601                   _M_get_Tp_allocator());
00602             _M_deallocate(__new_start, __len);
00603             __throw_exception_again;
00604           }
00605         std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
00606                   _M_get_Tp_allocator());
00607         _M_deallocate(this->_M_impl._M_start,
00608                   this->_M_impl._M_end_of_storage
00609                   - this->_M_impl._M_start);
00610         this->_M_impl._M_start = __new_start;
00611         this->_M_impl._M_finish = __new_finish;
00612         this->_M_impl._M_end_of_storage = __new_start + __len;
00613           }
00614       }
00615       }
00616 
00617 
00618   // vector<bool>
00619 
00620   template<typename _Alloc>
00621     void
00622     vector<bool, _Alloc>::
00623     reserve(size_type __n)
00624     {
00625       if (__n > this->max_size())
00626     __throw_length_error(__N("vector::reserve"));
00627       if (this->capacity() < __n)
00628     {
00629       _Bit_type* __q = this->_M_allocate(__n);
00630       this->_M_impl._M_finish = _M_copy_aligned(begin(), end(),
00631                             iterator(__q, 0));
00632       this->_M_deallocate();
00633       this->_M_impl._M_start = iterator(__q, 0);
00634       this->_M_impl._M_end_of_storage = (__q + (__n + int(_S_word_bit) - 1)
00635                          / int(_S_word_bit));
00636     }
00637     }
00638 
00639   template<typename _Alloc>
00640     void
00641     vector<bool, _Alloc>::
00642     _M_fill_insert(iterator __position, size_type __n, bool __x)
00643     {
00644       if (__n == 0)
00645     return;
00646       if (capacity() - size() >= __n)
00647     {
00648       std::copy_backward(__position, end(),
00649                  this->_M_impl._M_finish + difference_type(__n));
00650       std::fill(__position, __position + difference_type(__n), __x);
00651       this->_M_impl._M_finish += difference_type(__n);
00652     }
00653       else
00654     {
00655       const size_type __len = 
00656         _M_check_len(__n, "vector<bool>::_M_fill_insert");
00657       _Bit_type * __q = this->_M_allocate(__len);
00658       iterator __i = _M_copy_aligned(begin(), __position,
00659                      iterator(__q, 0));
00660       std::fill(__i, __i + difference_type(__n), __x);
00661       this->_M_impl._M_finish = std::copy(__position, end(),
00662                           __i + difference_type(__n));
00663       this->_M_deallocate();
00664       this->_M_impl._M_end_of_storage = (__q + ((__len
00665                              + int(_S_word_bit) - 1)
00666                             / int(_S_word_bit)));
00667       this->_M_impl._M_start = iterator(__q, 0);
00668     }
00669     }
00670 
00671   template<typename _Alloc>
00672     template<typename _ForwardIterator>
00673       void
00674       vector<bool, _Alloc>::
00675       _M_insert_range(iterator __position, _ForwardIterator __first, 
00676               _ForwardIterator __last, std::forward_iterator_tag)
00677       {
00678     if (__first != __last)
00679       {
00680         size_type __n = std::distance(__first, __last);
00681         if (capacity() - size() >= __n)
00682           {
00683         std::copy_backward(__position, end(),
00684                    this->_M_impl._M_finish
00685                    + difference_type(__n));
00686         std::copy(__first, __last, __position);
00687         this->_M_impl._M_finish += difference_type(__n);
00688           }
00689         else
00690           {
00691         const size_type __len =
00692           _M_check_len(__n, "vector<bool>::_M_insert_range");
00693         _Bit_type * __q = this->_M_allocate(__len);
00694         iterator __i = _M_copy_aligned(begin(), __position,
00695                            iterator(__q, 0));
00696         __i = std::copy(__first, __last, __i);
00697         this->_M_impl._M_finish = std::copy(__position, end(), __i);
00698         this->_M_deallocate();
00699         this->_M_impl._M_end_of_storage = (__q
00700                            + ((__len
00701                                + int(_S_word_bit) - 1)
00702                               / int(_S_word_bit)));
00703         this->_M_impl._M_start = iterator(__q, 0);
00704           }
00705       }
00706       }
00707 
00708   template<typename _Alloc>
00709     void
00710     vector<bool, _Alloc>::
00711     _M_insert_aux(iterator __position, bool __x)
00712     {
00713       if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
00714     {
00715       std::copy_backward(__position, this->_M_impl._M_finish, 
00716                  this->_M_impl._M_finish + 1);
00717       *__position = __x;
00718       ++this->_M_impl._M_finish;
00719     }
00720       else
00721     {
00722       const size_type __len =
00723         _M_check_len(size_type(1), "vector<bool>::_M_insert_aux");
00724       _Bit_type * __q = this->_M_allocate(__len);
00725       iterator __i = _M_copy_aligned(begin(), __position,
00726                      iterator(__q, 0));
00727       *__i++ = __x;
00728       this->_M_impl._M_finish = std::copy(__position, end(), __i);
00729       this->_M_deallocate();
00730       this->_M_impl._M_end_of_storage = (__q + ((__len
00731                              + int(_S_word_bit) - 1)
00732                             / int(_S_word_bit)));
00733       this->_M_impl._M_start = iterator(__q, 0);
00734     }
00735     }
00736 
00737 _GLIBCXX_END_NAMESPACE_CONTAINER
00738 } // namespace std
00739 
00740 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00741 
00742 namespace std _GLIBCXX_VISIBILITY(default)
00743 {
00744 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00745 
00746   template<typename _Alloc>
00747     size_t
00748     hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>::
00749     operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b) const
00750     {
00751       size_t __hash = 0;
00752       using _GLIBCXX_STD_C::_S_word_bit;
00753       using _GLIBCXX_STD_C::_Bit_type;
00754 
00755       const size_t __words = __b.size() / _S_word_bit;
00756       if (__words)
00757     {
00758       const size_t __clength = __words * sizeof(_Bit_type);
00759       __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength);
00760     }
00761 
00762       const size_t __extrabits = __b.size() % _S_word_bit;
00763       if (__extrabits)
00764     {
00765       _Bit_type __hiword = *__b._M_impl._M_finish._M_p;
00766       __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
00767 
00768       const size_t __clength
00769         = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
00770       if (__words)
00771         __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash);
00772       else
00773         __hash = std::_Hash_impl::hash(&__hiword, __clength);
00774     }
00775 
00776       return __hash;
00777     }
00778 
00779 _GLIBCXX_END_NAMESPACE_VERSION
00780 } // namespace std
00781 
00782 #endif // __GXX_EXPERIMENTAL_CXX0X__
00783 
00784 #endif /* _VECTOR_TCC */