1 // Vector implementation (out of line) -*- C++ -*-
3 // Copyright (C) 2001-2014 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
28 * Hewlett-Packard Company
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
40 * Silicon Graphics Computer Systems, Inc.
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
51 /** @file bits/vector.tcc
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{vector}
59 namespace std _GLIBCXX_VISIBILITY(default)
61 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
63 template<typename _Tp, typename _Alloc>
66 reserve(size_type __n)
68 if (__n > this->max_size())
69 __throw_length_error(__N("vector::reserve"));
70 if (this->capacity() < __n)
72 const size_type __old_size = size();
73 pointer __tmp = _M_allocate_and_copy(__n,
74 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start),
75 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish));
76 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
77 _M_get_Tp_allocator());
78 _M_deallocate(this->_M_impl._M_start,
79 this->_M_impl._M_end_of_storage
80 - this->_M_impl._M_start);
81 this->_M_impl._M_start = __tmp;
82 this->_M_impl._M_finish = __tmp + __old_size;
83 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
87 #if __cplusplus >= 201103L
88 template<typename _Tp, typename _Alloc>
89 template<typename... _Args>
92 emplace_back(_Args&&... __args)
94 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
96 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
97 std::forward<_Args>(__args)...);
98 ++this->_M_impl._M_finish;
101 _M_emplace_back_aux(std::forward<_Args>(__args)...);
105 template<typename _Tp, typename _Alloc>
106 typename vector<_Tp, _Alloc>::iterator
107 vector<_Tp, _Alloc>::
108 #if __cplusplus >= 201103L
109 insert(const_iterator __position, const value_type& __x)
111 insert(iterator __position, const value_type& __x)
114 const size_type __n = __position - begin();
115 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
116 && __position == end())
118 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, __x);
119 ++this->_M_impl._M_finish;
123 #if __cplusplus >= 201103L
124 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
127 _M_insert_aux(__position._M_const_cast(), std::move(__x_copy));
131 _M_insert_aux(__position._M_const_cast(), __x);
133 return iterator(this->_M_impl._M_start + __n);
136 template<typename _Tp, typename _Alloc>
137 typename vector<_Tp, _Alloc>::iterator
138 vector<_Tp, _Alloc>::
139 _M_erase(iterator __position)
141 if (__position + 1 != end())
142 _GLIBCXX_MOVE3(__position + 1, end(), __position);
143 --this->_M_impl._M_finish;
144 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
148 template<typename _Tp, typename _Alloc>
149 typename vector<_Tp, _Alloc>::iterator
150 vector<_Tp, _Alloc>::
151 _M_erase(iterator __first, iterator __last)
153 if (__first != __last)
156 _GLIBCXX_MOVE3(__last, end(), __first);
157 _M_erase_at_end(__first.base() + (end() - __last));
162 template<typename _Tp, typename _Alloc>
164 vector<_Tp, _Alloc>::
165 operator=(const vector<_Tp, _Alloc>& __x)
169 #if __cplusplus >= 201103L
170 if (_Alloc_traits::_S_propagate_on_copy_assign())
172 if (!_Alloc_traits::_S_always_equal()
173 && _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
175 // replacement allocator cannot free existing storage
177 _M_deallocate(this->_M_impl._M_start,
178 this->_M_impl._M_end_of_storage
179 - this->_M_impl._M_start);
180 this->_M_impl._M_start = nullptr;
181 this->_M_impl._M_finish = nullptr;
182 this->_M_impl._M_end_of_storage = nullptr;
184 std::__alloc_on_copy(_M_get_Tp_allocator(),
185 __x._M_get_Tp_allocator());
188 const size_type __xlen = __x.size();
189 if (__xlen > capacity())
191 pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(),
193 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
194 _M_get_Tp_allocator());
195 _M_deallocate(this->_M_impl._M_start,
196 this->_M_impl._M_end_of_storage
197 - this->_M_impl._M_start);
198 this->_M_impl._M_start = __tmp;
199 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
201 else if (size() >= __xlen)
203 std::_Destroy(std::copy(__x.begin(), __x.end(), begin()),
204 end(), _M_get_Tp_allocator());
208 std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(),
209 this->_M_impl._M_start);
210 std::__uninitialized_copy_a(__x._M_impl._M_start + size(),
211 __x._M_impl._M_finish,
212 this->_M_impl._M_finish,
213 _M_get_Tp_allocator());
215 this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
220 template<typename _Tp, typename _Alloc>
222 vector<_Tp, _Alloc>::
223 _M_fill_assign(size_t __n, const value_type& __val)
225 if (__n > capacity())
227 vector __tmp(__n, __val, _M_get_Tp_allocator());
230 else if (__n > size())
232 std::fill(begin(), end(), __val);
233 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
235 _M_get_Tp_allocator());
236 this->_M_impl._M_finish += __n - size();
239 _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val));
242 template<typename _Tp, typename _Alloc>
243 template<typename _InputIterator>
245 vector<_Tp, _Alloc>::
246 _M_assign_aux(_InputIterator __first, _InputIterator __last,
247 std::input_iterator_tag)
249 pointer __cur(this->_M_impl._M_start);
250 for (; __first != __last && __cur != this->_M_impl._M_finish;
253 if (__first == __last)
254 _M_erase_at_end(__cur);
256 insert(end(), __first, __last);
259 template<typename _Tp, typename _Alloc>
260 template<typename _ForwardIterator>
262 vector<_Tp, _Alloc>::
263 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
264 std::forward_iterator_tag)
266 const size_type __len = std::distance(__first, __last);
268 if (__len > capacity())
270 pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
271 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
272 _M_get_Tp_allocator());
273 _M_deallocate(this->_M_impl._M_start,
274 this->_M_impl._M_end_of_storage
275 - this->_M_impl._M_start);
276 this->_M_impl._M_start = __tmp;
277 this->_M_impl._M_finish = this->_M_impl._M_start + __len;
278 this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
280 else if (size() >= __len)
281 _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
284 _ForwardIterator __mid = __first;
285 std::advance(__mid, size());
286 std::copy(__first, __mid, this->_M_impl._M_start);
287 this->_M_impl._M_finish =
288 std::__uninitialized_copy_a(__mid, __last,
289 this->_M_impl._M_finish,
290 _M_get_Tp_allocator());
294 #if __cplusplus >= 201103L
295 template<typename _Tp, typename _Alloc>
296 template<typename... _Args>
297 typename vector<_Tp, _Alloc>::iterator
298 vector<_Tp, _Alloc>::
299 emplace(const_iterator __position, _Args&&... __args)
301 const size_type __n = __position - begin();
302 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
303 && __position == end())
305 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
306 std::forward<_Args>(__args)...);
307 ++this->_M_impl._M_finish;
310 _M_insert_aux(__position._M_const_cast(),
311 std::forward<_Args>(__args)...);
312 return iterator(this->_M_impl._M_start + __n);
315 template<typename _Tp, typename _Alloc>
316 template<typename... _Args>
318 vector<_Tp, _Alloc>::
319 _M_insert_aux(iterator __position, _Args&&... __args)
321 template<typename _Tp, typename _Alloc>
323 vector<_Tp, _Alloc>::
324 _M_insert_aux(iterator __position, const _Tp& __x)
327 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
329 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
330 _GLIBCXX_MOVE(*(this->_M_impl._M_finish
332 ++this->_M_impl._M_finish;
333 #if __cplusplus < 201103L
336 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
337 this->_M_impl._M_finish - 2,
338 this->_M_impl._M_finish - 1);
339 #if __cplusplus < 201103L
340 *__position = __x_copy;
342 *__position = _Tp(std::forward<_Args>(__args)...);
347 const size_type __len =
348 _M_check_len(size_type(1), "vector::_M_insert_aux");
349 const size_type __elems_before = __position - begin();
350 pointer __new_start(this->_M_allocate(__len));
351 pointer __new_finish(__new_start);
354 // The order of the three operations is dictated by the C++0x
355 // case, where the moves could alter a new element belonging
356 // to the existing vector. This is an issue only for callers
357 // taking the element by const lvalue ref (see 23.1/13).
358 _Alloc_traits::construct(this->_M_impl,
359 __new_start + __elems_before,
360 #if __cplusplus >= 201103L
361 std::forward<_Args>(__args)...);
365 __new_finish = pointer();
368 = std::__uninitialized_move_if_noexcept_a
369 (this->_M_impl._M_start, __position.base(),
370 __new_start, _M_get_Tp_allocator());
375 = std::__uninitialized_move_if_noexcept_a
376 (__position.base(), this->_M_impl._M_finish,
377 __new_finish, _M_get_Tp_allocator());
382 _Alloc_traits::destroy(this->_M_impl,
383 __new_start + __elems_before);
385 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
386 _M_deallocate(__new_start, __len);
387 __throw_exception_again;
389 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
390 _M_get_Tp_allocator());
391 _M_deallocate(this->_M_impl._M_start,
392 this->_M_impl._M_end_of_storage
393 - this->_M_impl._M_start);
394 this->_M_impl._M_start = __new_start;
395 this->_M_impl._M_finish = __new_finish;
396 this->_M_impl._M_end_of_storage = __new_start + __len;
400 #if __cplusplus >= 201103L
401 template<typename _Tp, typename _Alloc>
402 template<typename... _Args>
404 vector<_Tp, _Alloc>::
405 _M_emplace_back_aux(_Args&&... __args)
407 const size_type __len =
408 _M_check_len(size_type(1), "vector::_M_emplace_back_aux");
409 pointer __new_start(this->_M_allocate(__len));
410 pointer __new_finish(__new_start);
413 _Alloc_traits::construct(this->_M_impl, __new_start + size(),
414 std::forward<_Args>(__args)...);
415 __new_finish = pointer();
418 = std::__uninitialized_move_if_noexcept_a
419 (this->_M_impl._M_start, this->_M_impl._M_finish,
420 __new_start, _M_get_Tp_allocator());
427 _Alloc_traits::destroy(this->_M_impl, __new_start + size());
429 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
430 _M_deallocate(__new_start, __len);
431 __throw_exception_again;
433 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
434 _M_get_Tp_allocator());
435 _M_deallocate(this->_M_impl._M_start,
436 this->_M_impl._M_end_of_storage
437 - this->_M_impl._M_start);
438 this->_M_impl._M_start = __new_start;
439 this->_M_impl._M_finish = __new_finish;
440 this->_M_impl._M_end_of_storage = __new_start + __len;
444 template<typename _Tp, typename _Alloc>
446 vector<_Tp, _Alloc>::
447 _M_fill_insert(iterator __position, size_type __n, const value_type& __x)
451 if (size_type(this->_M_impl._M_end_of_storage
452 - this->_M_impl._M_finish) >= __n)
454 value_type __x_copy = __x;
455 const size_type __elems_after = end() - __position;
456 pointer __old_finish(this->_M_impl._M_finish);
457 if (__elems_after > __n)
459 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
460 this->_M_impl._M_finish,
461 this->_M_impl._M_finish,
462 _M_get_Tp_allocator());
463 this->_M_impl._M_finish += __n;
464 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
465 __old_finish - __n, __old_finish);
466 std::fill(__position.base(), __position.base() + __n,
471 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
474 _M_get_Tp_allocator());
475 this->_M_impl._M_finish += __n - __elems_after;
476 std::__uninitialized_move_a(__position.base(), __old_finish,
477 this->_M_impl._M_finish,
478 _M_get_Tp_allocator());
479 this->_M_impl._M_finish += __elems_after;
480 std::fill(__position.base(), __old_finish, __x_copy);
485 const size_type __len =
486 _M_check_len(__n, "vector::_M_fill_insert");
487 const size_type __elems_before = __position - begin();
488 pointer __new_start(this->_M_allocate(__len));
489 pointer __new_finish(__new_start);
492 // See _M_insert_aux above.
493 std::__uninitialized_fill_n_a(__new_start + __elems_before,
495 _M_get_Tp_allocator());
496 __new_finish = pointer();
499 = std::__uninitialized_move_if_noexcept_a
500 (this->_M_impl._M_start, __position.base(),
501 __new_start, _M_get_Tp_allocator());
506 = std::__uninitialized_move_if_noexcept_a
507 (__position.base(), this->_M_impl._M_finish,
508 __new_finish, _M_get_Tp_allocator());
513 std::_Destroy(__new_start + __elems_before,
514 __new_start + __elems_before + __n,
515 _M_get_Tp_allocator());
517 std::_Destroy(__new_start, __new_finish,
518 _M_get_Tp_allocator());
519 _M_deallocate(__new_start, __len);
520 __throw_exception_again;
522 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
523 _M_get_Tp_allocator());
524 _M_deallocate(this->_M_impl._M_start,
525 this->_M_impl._M_end_of_storage
526 - this->_M_impl._M_start);
527 this->_M_impl._M_start = __new_start;
528 this->_M_impl._M_finish = __new_finish;
529 this->_M_impl._M_end_of_storage = __new_start + __len;
534 #if __cplusplus >= 201103L
535 template<typename _Tp, typename _Alloc>
537 vector<_Tp, _Alloc>::
538 _M_default_append(size_type __n)
542 if (size_type(this->_M_impl._M_end_of_storage
543 - this->_M_impl._M_finish) >= __n)
545 std::__uninitialized_default_n_a(this->_M_impl._M_finish,
546 __n, _M_get_Tp_allocator());
547 this->_M_impl._M_finish += __n;
551 const size_type __len =
552 _M_check_len(__n, "vector::_M_default_append");
553 const size_type __old_size = this->size();
554 pointer __new_start(this->_M_allocate(__len));
555 pointer __new_finish(__new_start);
559 = std::__uninitialized_move_if_noexcept_a
560 (this->_M_impl._M_start, this->_M_impl._M_finish,
561 __new_start, _M_get_Tp_allocator());
562 std::__uninitialized_default_n_a(__new_finish, __n,
563 _M_get_Tp_allocator());
568 std::_Destroy(__new_start, __new_finish,
569 _M_get_Tp_allocator());
570 _M_deallocate(__new_start, __len);
571 __throw_exception_again;
573 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
574 _M_get_Tp_allocator());
575 _M_deallocate(this->_M_impl._M_start,
576 this->_M_impl._M_end_of_storage
577 - this->_M_impl._M_start);
578 this->_M_impl._M_start = __new_start;
579 this->_M_impl._M_finish = __new_finish;
580 this->_M_impl._M_end_of_storage = __new_start + __len;
585 template<typename _Tp, typename _Alloc>
587 vector<_Tp, _Alloc>::
590 if (capacity() == size())
592 return std::__shrink_to_fit_aux<vector>::_S_do_it(*this);
596 template<typename _Tp, typename _Alloc>
597 template<typename _InputIterator>
599 vector<_Tp, _Alloc>::
600 _M_range_insert(iterator __pos, _InputIterator __first,
601 _InputIterator __last, std::input_iterator_tag)
603 for (; __first != __last; ++__first)
605 __pos = insert(__pos, *__first);
610 template<typename _Tp, typename _Alloc>
611 template<typename _ForwardIterator>
613 vector<_Tp, _Alloc>::
614 _M_range_insert(iterator __position, _ForwardIterator __first,
615 _ForwardIterator __last, std::forward_iterator_tag)
617 if (__first != __last)
619 const size_type __n = std::distance(__first, __last);
620 if (size_type(this->_M_impl._M_end_of_storage
621 - this->_M_impl._M_finish) >= __n)
623 const size_type __elems_after = end() - __position;
624 pointer __old_finish(this->_M_impl._M_finish);
625 if (__elems_after > __n)
627 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
628 this->_M_impl._M_finish,
629 this->_M_impl._M_finish,
630 _M_get_Tp_allocator());
631 this->_M_impl._M_finish += __n;
632 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
633 __old_finish - __n, __old_finish);
634 std::copy(__first, __last, __position);
638 _ForwardIterator __mid = __first;
639 std::advance(__mid, __elems_after);
640 std::__uninitialized_copy_a(__mid, __last,
641 this->_M_impl._M_finish,
642 _M_get_Tp_allocator());
643 this->_M_impl._M_finish += __n - __elems_after;
644 std::__uninitialized_move_a(__position.base(),
646 this->_M_impl._M_finish,
647 _M_get_Tp_allocator());
648 this->_M_impl._M_finish += __elems_after;
649 std::copy(__first, __mid, __position);
654 const size_type __len =
655 _M_check_len(__n, "vector::_M_range_insert");
656 pointer __new_start(this->_M_allocate(__len));
657 pointer __new_finish(__new_start);
661 = std::__uninitialized_move_if_noexcept_a
662 (this->_M_impl._M_start, __position.base(),
663 __new_start, _M_get_Tp_allocator());
665 = std::__uninitialized_copy_a(__first, __last,
667 _M_get_Tp_allocator());
669 = std::__uninitialized_move_if_noexcept_a
670 (__position.base(), this->_M_impl._M_finish,
671 __new_finish, _M_get_Tp_allocator());
675 std::_Destroy(__new_start, __new_finish,
676 _M_get_Tp_allocator());
677 _M_deallocate(__new_start, __len);
678 __throw_exception_again;
680 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
681 _M_get_Tp_allocator());
682 _M_deallocate(this->_M_impl._M_start,
683 this->_M_impl._M_end_of_storage
684 - this->_M_impl._M_start);
685 this->_M_impl._M_start = __new_start;
686 this->_M_impl._M_finish = __new_finish;
687 this->_M_impl._M_end_of_storage = __new_start + __len;
694 template<typename _Alloc>
696 vector<bool, _Alloc>::
697 _M_reallocate(size_type __n)
699 _Bit_type* __q = this->_M_allocate(__n);
700 this->_M_impl._M_finish = _M_copy_aligned(begin(), end(),
702 this->_M_deallocate();
703 this->_M_impl._M_start = iterator(__q, 0);
704 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
707 template<typename _Alloc>
709 vector<bool, _Alloc>::
710 _M_fill_insert(iterator __position, size_type __n, bool __x)
714 if (capacity() - size() >= __n)
716 std::copy_backward(__position, end(),
717 this->_M_impl._M_finish + difference_type(__n));
718 std::fill(__position, __position + difference_type(__n), __x);
719 this->_M_impl._M_finish += difference_type(__n);
723 const size_type __len =
724 _M_check_len(__n, "vector<bool>::_M_fill_insert");
725 _Bit_type * __q = this->_M_allocate(__len);
726 iterator __i = _M_copy_aligned(begin(), __position,
728 std::fill(__i, __i + difference_type(__n), __x);
729 this->_M_impl._M_finish = std::copy(__position, end(),
730 __i + difference_type(__n));
731 this->_M_deallocate();
732 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
733 this->_M_impl._M_start = iterator(__q, 0);
737 template<typename _Alloc>
738 template<typename _ForwardIterator>
740 vector<bool, _Alloc>::
741 _M_insert_range(iterator __position, _ForwardIterator __first,
742 _ForwardIterator __last, std::forward_iterator_tag)
744 if (__first != __last)
746 size_type __n = std::distance(__first, __last);
747 if (capacity() - size() >= __n)
749 std::copy_backward(__position, end(),
750 this->_M_impl._M_finish
751 + difference_type(__n));
752 std::copy(__first, __last, __position);
753 this->_M_impl._M_finish += difference_type(__n);
757 const size_type __len =
758 _M_check_len(__n, "vector<bool>::_M_insert_range");
759 _Bit_type * __q = this->_M_allocate(__len);
760 iterator __i = _M_copy_aligned(begin(), __position,
762 __i = std::copy(__first, __last, __i);
763 this->_M_impl._M_finish = std::copy(__position, end(), __i);
764 this->_M_deallocate();
765 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
766 this->_M_impl._M_start = iterator(__q, 0);
771 template<typename _Alloc>
773 vector<bool, _Alloc>::
774 _M_insert_aux(iterator __position, bool __x)
776 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
778 std::copy_backward(__position, this->_M_impl._M_finish,
779 this->_M_impl._M_finish + 1);
781 ++this->_M_impl._M_finish;
785 const size_type __len =
786 _M_check_len(size_type(1), "vector<bool>::_M_insert_aux");
787 _Bit_type * __q = this->_M_allocate(__len);
788 iterator __i = _M_copy_aligned(begin(), __position,
791 this->_M_impl._M_finish = std::copy(__position, end(), __i);
792 this->_M_deallocate();
793 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
794 this->_M_impl._M_start = iterator(__q, 0);
798 template<typename _Alloc>
799 typename vector<bool, _Alloc>::iterator
800 vector<bool, _Alloc>::
801 _M_erase(iterator __position)
803 if (__position + 1 != end())
804 std::copy(__position + 1, end(), __position);
805 --this->_M_impl._M_finish;
809 template<typename _Alloc>
810 typename vector<bool, _Alloc>::iterator
811 vector<bool, _Alloc>::
812 _M_erase(iterator __first, iterator __last)
814 if (__first != __last)
815 _M_erase_at_end(std::copy(__last, end(), __first));
819 #if __cplusplus >= 201103L
820 template<typename _Alloc>
822 vector<bool, _Alloc>::
825 if (capacity() - size() < int(_S_word_bit))
829 _M_reallocate(size());
837 _GLIBCXX_END_NAMESPACE_CONTAINER
840 #if __cplusplus >= 201103L
842 namespace std _GLIBCXX_VISIBILITY(default)
844 _GLIBCXX_BEGIN_NAMESPACE_VERSION
846 template<typename _Alloc>
848 hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>::
849 operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b) const noexcept
852 using _GLIBCXX_STD_C::_S_word_bit;
853 using _GLIBCXX_STD_C::_Bit_type;
855 const size_t __words = __b.size() / _S_word_bit;
858 const size_t __clength = __words * sizeof(_Bit_type);
859 __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength);
862 const size_t __extrabits = __b.size() % _S_word_bit;
865 _Bit_type __hiword = *__b._M_impl._M_finish._M_p;
866 __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
868 const size_t __clength
869 = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
871 __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash);
873 __hash = std::_Hash_impl::hash(&__hiword, __clength);
879 _GLIBCXX_END_NAMESPACE_VERSION
884 #endif /* _VECTOR_TCC */