1 // Vector implementation (out of line) -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc.
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 3, or (at your option)
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 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
29 * Hewlett-Packard Company
31 * Permission to use, copy, modify, distribute and sell this software
32 * and its documentation for any purpose is hereby granted without fee,
33 * provided that the above copyright notice appear in all copies and
34 * that both that copyright notice and this permission notice appear
35 * in supporting documentation. Hewlett-Packard Company makes no
36 * representations about the suitability of this software for any
37 * purpose. It is provided "as is" without express or implied warranty.
41 * Silicon Graphics Computer Systems, Inc.
43 * Permission to use, copy, modify, distribute and sell this software
44 * and its documentation for any purpose is hereby granted without fee,
45 * provided that the above copyright notice appear in all copies and
46 * that both that copyright notice and this permission notice appear
47 * in supporting documentation. Silicon Graphics makes no
48 * representations about the suitability of this software for any
49 * purpose. It is provided "as is" without express or implied warranty.
52 /** @file bits/vector.tcc
53 * This is an internal header file, included by other library headers.
54 * Do not attempt to use it directly. @headername{vector}
60 namespace std _GLIBCXX_VISIBILITY(default)
62 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
64 template<typename _Tp, typename _Alloc>
67 reserve(size_type __n)
69 if (__n > this->max_size())
70 __throw_length_error(__N("vector::reserve"));
71 if (this->capacity() < __n)
73 const size_type __old_size = size();
74 pointer __tmp = _M_allocate_and_copy(__n,
75 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start),
76 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish));
77 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
78 _M_get_Tp_allocator());
79 _M_deallocate(this->_M_impl._M_start,
80 this->_M_impl._M_end_of_storage
81 - this->_M_impl._M_start);
82 this->_M_impl._M_start = __tmp;
83 this->_M_impl._M_finish = __tmp + __old_size;
84 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
88 #ifdef __GXX_EXPERIMENTAL_CXX0X__
89 template<typename _Tp, typename _Alloc>
90 template<typename... _Args>
93 emplace_back(_Args&&... __args)
95 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
97 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
98 std::forward<_Args>(__args)...);
99 ++this->_M_impl._M_finish;
102 _M_emplace_back_aux(std::forward<_Args>(__args)...);
106 template<typename _Tp, typename _Alloc>
107 typename vector<_Tp, _Alloc>::iterator
108 vector<_Tp, _Alloc>::
109 insert(iterator __position, const value_type& __x)
111 const size_type __n = __position - begin();
112 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
113 && __position == end())
115 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, __x);
116 ++this->_M_impl._M_finish;
120 #ifdef __GXX_EXPERIMENTAL_CXX0X__
121 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
124 _M_insert_aux(__position, std::move(__x_copy));
128 _M_insert_aux(__position, __x);
130 return iterator(this->_M_impl._M_start + __n);
133 template<typename _Tp, typename _Alloc>
134 typename vector<_Tp, _Alloc>::iterator
135 vector<_Tp, _Alloc>::
136 erase(iterator __position)
138 if (__position + 1 != end())
139 _GLIBCXX_MOVE3(__position + 1, end(), __position);
140 --this->_M_impl._M_finish;
141 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
145 template<typename _Tp, typename _Alloc>
146 typename vector<_Tp, _Alloc>::iterator
147 vector<_Tp, _Alloc>::
148 erase(iterator __first, iterator __last)
151 _GLIBCXX_MOVE3(__last, end(), __first);
152 _M_erase_at_end(__first.base() + (end() - __last));
156 template<typename _Tp, typename _Alloc>
158 vector<_Tp, _Alloc>::
159 operator=(const vector<_Tp, _Alloc>& __x)
163 #ifdef __GXX_EXPERIMENTAL_CXX0X__
164 if (_Alloc_traits::_S_propagate_on_copy_assign())
166 if (!_Alloc_traits::_S_always_equal()
167 && _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
169 // replacement allocator cannot free existing storage
171 _M_deallocate(this->_M_impl._M_start,
172 this->_M_impl._M_end_of_storage
173 - this->_M_impl._M_start);
175 std::__alloc_on_copy(_M_get_Tp_allocator(),
176 __x._M_get_Tp_allocator());
179 const size_type __xlen = __x.size();
180 if (__xlen > capacity())
182 pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(),
184 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
185 _M_get_Tp_allocator());
186 _M_deallocate(this->_M_impl._M_start,
187 this->_M_impl._M_end_of_storage
188 - this->_M_impl._M_start);
189 this->_M_impl._M_start = __tmp;
190 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
192 else if (size() >= __xlen)
194 std::_Destroy(std::copy(__x.begin(), __x.end(), begin()),
195 end(), _M_get_Tp_allocator());
199 std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(),
200 this->_M_impl._M_start);
201 std::__uninitialized_copy_a(__x._M_impl._M_start + size(),
202 __x._M_impl._M_finish,
203 this->_M_impl._M_finish,
204 _M_get_Tp_allocator());
206 this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
211 template<typename _Tp, typename _Alloc>
213 vector<_Tp, _Alloc>::
214 _M_fill_assign(size_t __n, const value_type& __val)
216 if (__n > capacity())
218 vector __tmp(__n, __val, _M_get_Tp_allocator());
221 else if (__n > size())
223 std::fill(begin(), end(), __val);
224 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
226 _M_get_Tp_allocator());
227 this->_M_impl._M_finish += __n - size();
230 _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val));
233 template<typename _Tp, typename _Alloc>
234 template<typename _InputIterator>
236 vector<_Tp, _Alloc>::
237 _M_assign_aux(_InputIterator __first, _InputIterator __last,
238 std::input_iterator_tag)
240 pointer __cur(this->_M_impl._M_start);
241 for (; __first != __last && __cur != this->_M_impl._M_finish;
244 if (__first == __last)
245 _M_erase_at_end(__cur);
247 insert(end(), __first, __last);
250 template<typename _Tp, typename _Alloc>
251 template<typename _ForwardIterator>
253 vector<_Tp, _Alloc>::
254 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
255 std::forward_iterator_tag)
257 const size_type __len = std::distance(__first, __last);
259 if (__len > capacity())
261 pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
262 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
263 _M_get_Tp_allocator());
264 _M_deallocate(this->_M_impl._M_start,
265 this->_M_impl._M_end_of_storage
266 - this->_M_impl._M_start);
267 this->_M_impl._M_start = __tmp;
268 this->_M_impl._M_finish = this->_M_impl._M_start + __len;
269 this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
271 else if (size() >= __len)
272 _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
275 _ForwardIterator __mid = __first;
276 std::advance(__mid, size());
277 std::copy(__first, __mid, this->_M_impl._M_start);
278 this->_M_impl._M_finish =
279 std::__uninitialized_copy_a(__mid, __last,
280 this->_M_impl._M_finish,
281 _M_get_Tp_allocator());
285 #ifdef __GXX_EXPERIMENTAL_CXX0X__
286 template<typename _Tp, typename _Alloc>
287 template<typename... _Args>
288 typename vector<_Tp, _Alloc>::iterator
289 vector<_Tp, _Alloc>::
290 emplace(iterator __position, _Args&&... __args)
292 const size_type __n = __position - begin();
293 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
294 && __position == end())
296 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
297 std::forward<_Args>(__args)...);
298 ++this->_M_impl._M_finish;
301 _M_insert_aux(__position, std::forward<_Args>(__args)...);
302 return iterator(this->_M_impl._M_start + __n);
305 template<typename _Tp, typename _Alloc>
306 template<typename... _Args>
308 vector<_Tp, _Alloc>::
309 _M_insert_aux(iterator __position, _Args&&... __args)
311 template<typename _Tp, typename _Alloc>
313 vector<_Tp, _Alloc>::
314 _M_insert_aux(iterator __position, const _Tp& __x)
317 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
319 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
320 _GLIBCXX_MOVE(*(this->_M_impl._M_finish
322 ++this->_M_impl._M_finish;
323 #ifndef __GXX_EXPERIMENTAL_CXX0X__
326 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
327 this->_M_impl._M_finish - 2,
328 this->_M_impl._M_finish - 1);
329 #ifndef __GXX_EXPERIMENTAL_CXX0X__
330 *__position = __x_copy;
332 *__position = _Tp(std::forward<_Args>(__args)...);
337 const size_type __len =
338 _M_check_len(size_type(1), "vector::_M_insert_aux");
339 const size_type __elems_before = __position - begin();
340 pointer __new_start(this->_M_allocate(__len));
341 pointer __new_finish(__new_start);
344 // The order of the three operations is dictated by the C++0x
345 // case, where the moves could alter a new element belonging
346 // to the existing vector. This is an issue only for callers
347 // taking the element by const lvalue ref (see 23.1/13).
348 _Alloc_traits::construct(this->_M_impl,
349 __new_start + __elems_before,
350 #ifdef __GXX_EXPERIMENTAL_CXX0X__
351 std::forward<_Args>(__args)...);
358 = std::__uninitialized_move_if_noexcept_a
359 (this->_M_impl._M_start, __position.base(),
360 __new_start, _M_get_Tp_allocator());
365 = std::__uninitialized_move_if_noexcept_a
366 (__position.base(), this->_M_impl._M_finish,
367 __new_finish, _M_get_Tp_allocator());
372 _Alloc_traits::destroy(this->_M_impl,
373 __new_start + __elems_before);
375 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
376 _M_deallocate(__new_start, __len);
377 __throw_exception_again;
379 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
380 _M_get_Tp_allocator());
381 _M_deallocate(this->_M_impl._M_start,
382 this->_M_impl._M_end_of_storage
383 - this->_M_impl._M_start);
384 this->_M_impl._M_start = __new_start;
385 this->_M_impl._M_finish = __new_finish;
386 this->_M_impl._M_end_of_storage = __new_start + __len;
390 #ifdef __GXX_EXPERIMENTAL_CXX0X__
391 template<typename _Tp, typename _Alloc>
392 template<typename... _Args>
394 vector<_Tp, _Alloc>::
395 _M_emplace_back_aux(_Args&&... __args)
397 const size_type __len =
398 _M_check_len(size_type(1), "vector::_M_emplace_back_aux");
399 pointer __new_start(this->_M_allocate(__len));
400 pointer __new_finish(__new_start);
403 _Alloc_traits::construct(this->_M_impl, __new_start + size(),
404 std::forward<_Args>(__args)...);
408 = std::__uninitialized_move_if_noexcept_a
409 (this->_M_impl._M_start, this->_M_impl._M_finish,
410 __new_start, _M_get_Tp_allocator());
417 _Alloc_traits::destroy(this->_M_impl, __new_start + size());
419 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
420 _M_deallocate(__new_start, __len);
421 __throw_exception_again;
423 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
424 _M_get_Tp_allocator());
425 _M_deallocate(this->_M_impl._M_start,
426 this->_M_impl._M_end_of_storage
427 - this->_M_impl._M_start);
428 this->_M_impl._M_start = __new_start;
429 this->_M_impl._M_finish = __new_finish;
430 this->_M_impl._M_end_of_storage = __new_start + __len;
434 template<typename _Tp, typename _Alloc>
436 vector<_Tp, _Alloc>::
437 _M_fill_insert(iterator __position, size_type __n, const value_type& __x)
441 if (size_type(this->_M_impl._M_end_of_storage
442 - this->_M_impl._M_finish) >= __n)
444 value_type __x_copy = __x;
445 const size_type __elems_after = end() - __position;
446 pointer __old_finish(this->_M_impl._M_finish);
447 if (__elems_after > __n)
449 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
450 this->_M_impl._M_finish,
451 this->_M_impl._M_finish,
452 _M_get_Tp_allocator());
453 this->_M_impl._M_finish += __n;
454 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
455 __old_finish - __n, __old_finish);
456 std::fill(__position.base(), __position.base() + __n,
461 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
464 _M_get_Tp_allocator());
465 this->_M_impl._M_finish += __n - __elems_after;
466 std::__uninitialized_move_a(__position.base(), __old_finish,
467 this->_M_impl._M_finish,
468 _M_get_Tp_allocator());
469 this->_M_impl._M_finish += __elems_after;
470 std::fill(__position.base(), __old_finish, __x_copy);
475 const size_type __len =
476 _M_check_len(__n, "vector::_M_fill_insert");
477 const size_type __elems_before = __position - begin();
478 pointer __new_start(this->_M_allocate(__len));
479 pointer __new_finish(__new_start);
482 // See _M_insert_aux above.
483 std::__uninitialized_fill_n_a(__new_start + __elems_before,
485 _M_get_Tp_allocator());
489 = std::__uninitialized_move_if_noexcept_a
490 (this->_M_impl._M_start, __position.base(),
491 __new_start, _M_get_Tp_allocator());
496 = std::__uninitialized_move_if_noexcept_a
497 (__position.base(), this->_M_impl._M_finish,
498 __new_finish, _M_get_Tp_allocator());
503 std::_Destroy(__new_start + __elems_before,
504 __new_start + __elems_before + __n,
505 _M_get_Tp_allocator());
507 std::_Destroy(__new_start, __new_finish,
508 _M_get_Tp_allocator());
509 _M_deallocate(__new_start, __len);
510 __throw_exception_again;
512 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
513 _M_get_Tp_allocator());
514 _M_deallocate(this->_M_impl._M_start,
515 this->_M_impl._M_end_of_storage
516 - this->_M_impl._M_start);
517 this->_M_impl._M_start = __new_start;
518 this->_M_impl._M_finish = __new_finish;
519 this->_M_impl._M_end_of_storage = __new_start + __len;
524 #ifdef __GXX_EXPERIMENTAL_CXX0X__
525 template<typename _Tp, typename _Alloc>
527 vector<_Tp, _Alloc>::
528 _M_default_append(size_type __n)
532 if (size_type(this->_M_impl._M_end_of_storage
533 - this->_M_impl._M_finish) >= __n)
535 std::__uninitialized_default_n_a(this->_M_impl._M_finish,
536 __n, _M_get_Tp_allocator());
537 this->_M_impl._M_finish += __n;
541 const size_type __len =
542 _M_check_len(__n, "vector::_M_default_append");
543 const size_type __old_size = this->size();
544 pointer __new_start(this->_M_allocate(__len));
545 pointer __new_finish(__new_start);
549 = std::__uninitialized_move_if_noexcept_a
550 (this->_M_impl._M_start, this->_M_impl._M_finish,
551 __new_start, _M_get_Tp_allocator());
552 std::__uninitialized_default_n_a(__new_finish, __n,
553 _M_get_Tp_allocator());
558 std::_Destroy(__new_start, __new_finish,
559 _M_get_Tp_allocator());
560 _M_deallocate(__new_start, __len);
561 __throw_exception_again;
563 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
564 _M_get_Tp_allocator());
565 _M_deallocate(this->_M_impl._M_start,
566 this->_M_impl._M_end_of_storage
567 - this->_M_impl._M_start);
568 this->_M_impl._M_start = __new_start;
569 this->_M_impl._M_finish = __new_finish;
570 this->_M_impl._M_end_of_storage = __new_start + __len;
575 template<typename _Tp, typename _Alloc>
577 vector<_Tp, _Alloc>::
580 if (capacity() == size())
582 return std::__shrink_to_fit_aux<vector>::_S_do_it(*this);
586 template<typename _Tp, typename _Alloc>
587 template<typename _InputIterator>
589 vector<_Tp, _Alloc>::
590 _M_range_insert(iterator __pos, _InputIterator __first,
591 _InputIterator __last, std::input_iterator_tag)
593 for (; __first != __last; ++__first)
595 __pos = insert(__pos, *__first);
600 template<typename _Tp, typename _Alloc>
601 template<typename _ForwardIterator>
603 vector<_Tp, _Alloc>::
604 _M_range_insert(iterator __position, _ForwardIterator __first,
605 _ForwardIterator __last, std::forward_iterator_tag)
607 if (__first != __last)
609 const size_type __n = std::distance(__first, __last);
610 if (size_type(this->_M_impl._M_end_of_storage
611 - this->_M_impl._M_finish) >= __n)
613 const size_type __elems_after = end() - __position;
614 pointer __old_finish(this->_M_impl._M_finish);
615 if (__elems_after > __n)
617 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
618 this->_M_impl._M_finish,
619 this->_M_impl._M_finish,
620 _M_get_Tp_allocator());
621 this->_M_impl._M_finish += __n;
622 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
623 __old_finish - __n, __old_finish);
624 std::copy(__first, __last, __position);
628 _ForwardIterator __mid = __first;
629 std::advance(__mid, __elems_after);
630 std::__uninitialized_copy_a(__mid, __last,
631 this->_M_impl._M_finish,
632 _M_get_Tp_allocator());
633 this->_M_impl._M_finish += __n - __elems_after;
634 std::__uninitialized_move_a(__position.base(),
636 this->_M_impl._M_finish,
637 _M_get_Tp_allocator());
638 this->_M_impl._M_finish += __elems_after;
639 std::copy(__first, __mid, __position);
644 const size_type __len =
645 _M_check_len(__n, "vector::_M_range_insert");
646 pointer __new_start(this->_M_allocate(__len));
647 pointer __new_finish(__new_start);
651 = std::__uninitialized_move_if_noexcept_a
652 (this->_M_impl._M_start, __position.base(),
653 __new_start, _M_get_Tp_allocator());
655 = std::__uninitialized_copy_a(__first, __last,
657 _M_get_Tp_allocator());
659 = std::__uninitialized_move_if_noexcept_a
660 (__position.base(), this->_M_impl._M_finish,
661 __new_finish, _M_get_Tp_allocator());
665 std::_Destroy(__new_start, __new_finish,
666 _M_get_Tp_allocator());
667 _M_deallocate(__new_start, __len);
668 __throw_exception_again;
670 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
671 _M_get_Tp_allocator());
672 _M_deallocate(this->_M_impl._M_start,
673 this->_M_impl._M_end_of_storage
674 - this->_M_impl._M_start);
675 this->_M_impl._M_start = __new_start;
676 this->_M_impl._M_finish = __new_finish;
677 this->_M_impl._M_end_of_storage = __new_start + __len;
684 template<typename _Alloc>
686 vector<bool, _Alloc>::
687 _M_reallocate(size_type __n)
689 _Bit_type* __q = this->_M_allocate(__n);
690 this->_M_impl._M_finish = _M_copy_aligned(begin(), end(),
692 this->_M_deallocate();
693 this->_M_impl._M_start = iterator(__q, 0);
694 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
697 template<typename _Alloc>
699 vector<bool, _Alloc>::
700 _M_fill_insert(iterator __position, size_type __n, bool __x)
704 if (capacity() - size() >= __n)
706 std::copy_backward(__position, end(),
707 this->_M_impl._M_finish + difference_type(__n));
708 std::fill(__position, __position + difference_type(__n), __x);
709 this->_M_impl._M_finish += difference_type(__n);
713 const size_type __len =
714 _M_check_len(__n, "vector<bool>::_M_fill_insert");
715 _Bit_type * __q = this->_M_allocate(__len);
716 iterator __i = _M_copy_aligned(begin(), __position,
718 std::fill(__i, __i + difference_type(__n), __x);
719 this->_M_impl._M_finish = std::copy(__position, end(),
720 __i + difference_type(__n));
721 this->_M_deallocate();
722 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
723 this->_M_impl._M_start = iterator(__q, 0);
727 template<typename _Alloc>
728 template<typename _ForwardIterator>
730 vector<bool, _Alloc>::
731 _M_insert_range(iterator __position, _ForwardIterator __first,
732 _ForwardIterator __last, std::forward_iterator_tag)
734 if (__first != __last)
736 size_type __n = std::distance(__first, __last);
737 if (capacity() - size() >= __n)
739 std::copy_backward(__position, end(),
740 this->_M_impl._M_finish
741 + difference_type(__n));
742 std::copy(__first, __last, __position);
743 this->_M_impl._M_finish += difference_type(__n);
747 const size_type __len =
748 _M_check_len(__n, "vector<bool>::_M_insert_range");
749 _Bit_type * __q = this->_M_allocate(__len);
750 iterator __i = _M_copy_aligned(begin(), __position,
752 __i = std::copy(__first, __last, __i);
753 this->_M_impl._M_finish = std::copy(__position, end(), __i);
754 this->_M_deallocate();
755 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
756 this->_M_impl._M_start = iterator(__q, 0);
761 template<typename _Alloc>
763 vector<bool, _Alloc>::
764 _M_insert_aux(iterator __position, bool __x)
766 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
768 std::copy_backward(__position, this->_M_impl._M_finish,
769 this->_M_impl._M_finish + 1);
771 ++this->_M_impl._M_finish;
775 const size_type __len =
776 _M_check_len(size_type(1), "vector<bool>::_M_insert_aux");
777 _Bit_type * __q = this->_M_allocate(__len);
778 iterator __i = _M_copy_aligned(begin(), __position,
781 this->_M_impl._M_finish = std::copy(__position, end(), __i);
782 this->_M_deallocate();
783 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
784 this->_M_impl._M_start = iterator(__q, 0);
788 #ifdef __GXX_EXPERIMENTAL_CXX0X__
789 template<typename _Alloc>
791 vector<bool, _Alloc>::
794 if (capacity() - size() < int(_S_word_bit))
798 _M_reallocate(size());
806 _GLIBCXX_END_NAMESPACE_CONTAINER
809 #ifdef __GXX_EXPERIMENTAL_CXX0X__
811 namespace std _GLIBCXX_VISIBILITY(default)
813 _GLIBCXX_BEGIN_NAMESPACE_VERSION
815 template<typename _Alloc>
817 hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>::
818 operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b) const
821 using _GLIBCXX_STD_C::_S_word_bit;
822 using _GLIBCXX_STD_C::_Bit_type;
824 const size_t __words = __b.size() / _S_word_bit;
827 const size_t __clength = __words * sizeof(_Bit_type);
828 __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength);
831 const size_t __extrabits = __b.size() % _S_word_bit;
834 _Bit_type __hiword = *__b._M_impl._M_finish._M_p;
835 __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
837 const size_t __clength
838 = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
840 __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash);
842 __hash = std::_Hash_impl::hash(&__hiword, __clength);
848 _GLIBCXX_END_NAMESPACE_VERSION
851 #endif // __GXX_EXPERIMENTAL_CXX0X__
853 #endif /* _VECTOR_TCC */