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