1 // vector<bool> specialization -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011, 2012 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.
40 * Copyright (c) 1996-1999
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/stl_bvector.h
53 * This is an internal header file, included by other library headers.
54 * Do not attempt to use it directly. @headername{vector}
57 #ifndef _STL_BVECTOR_H
58 #define _STL_BVECTOR_H 1
60 #ifdef __GXX_EXPERIMENTAL_CXX0X__
61 #include <initializer_list>
64 namespace std
_GLIBCXX_VISIBILITY(default)
66 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
68 typedef unsigned long _Bit_type
;
69 enum { _S_word_bit
= int(__CHAR_BIT__
* sizeof(_Bit_type
)) };
76 _Bit_reference(_Bit_type
* __x
, _Bit_type __y
)
77 : _M_p(__x
), _M_mask(__y
) { }
79 _Bit_reference() _GLIBCXX_NOEXCEPT
: _M_p(0), _M_mask(0) { }
81 operator bool() const _GLIBCXX_NOEXCEPT
82 { return !!(*_M_p
& _M_mask
); }
85 operator=(bool __x
) _GLIBCXX_NOEXCEPT
95 operator=(const _Bit_reference
& __x
) _GLIBCXX_NOEXCEPT
96 { return *this = bool(__x
); }
99 operator==(const _Bit_reference
& __x
) const
100 { return bool(*this) == bool(__x
); }
103 operator<(const _Bit_reference
& __x
) const
104 { return !bool(*this) && bool(__x
); }
107 flip() _GLIBCXX_NOEXCEPT
108 { *_M_p
^= _M_mask
; }
111 #ifdef __GXX_EXPERIMENTAL_CXX0X__
113 swap(_Bit_reference __x
, _Bit_reference __y
) noexcept
121 swap(_Bit_reference __x
, bool& __y
) noexcept
129 swap(bool& __x
, _Bit_reference __y
) noexcept
137 struct _Bit_iterator_base
138 : public std::iterator
<std::random_access_iterator_tag
, bool>
141 unsigned int _M_offset
;
143 _Bit_iterator_base(_Bit_type
* __x
, unsigned int __y
)
144 : _M_p(__x
), _M_offset(__y
) { }
149 if (_M_offset
++ == int(_S_word_bit
) - 1)
159 if (_M_offset
-- == 0)
161 _M_offset
= int(_S_word_bit
) - 1;
167 _M_incr(ptrdiff_t __i
)
169 difference_type __n
= __i
+ _M_offset
;
170 _M_p
+= __n
/ int(_S_word_bit
);
171 __n
= __n
% int(_S_word_bit
);
174 __n
+= int(_S_word_bit
);
177 _M_offset
= static_cast<unsigned int>(__n
);
181 operator==(const _Bit_iterator_base
& __i
) const
182 { return _M_p
== __i
._M_p
&& _M_offset
== __i
._M_offset
; }
185 operator<(const _Bit_iterator_base
& __i
) const
187 return _M_p
< __i
._M_p
188 || (_M_p
== __i
._M_p
&& _M_offset
< __i
._M_offset
);
192 operator!=(const _Bit_iterator_base
& __i
) const
193 { return !(*this == __i
); }
196 operator>(const _Bit_iterator_base
& __i
) const
197 { return __i
< *this; }
200 operator<=(const _Bit_iterator_base
& __i
) const
201 { return !(__i
< *this); }
204 operator>=(const _Bit_iterator_base
& __i
) const
205 { return !(*this < __i
); }
209 operator-(const _Bit_iterator_base
& __x
, const _Bit_iterator_base
& __y
)
211 return (int(_S_word_bit
) * (__x
._M_p
- __y
._M_p
)
212 + __x
._M_offset
- __y
._M_offset
);
215 struct _Bit_iterator
: public _Bit_iterator_base
217 typedef _Bit_reference reference
;
218 typedef _Bit_reference
* pointer
;
219 typedef _Bit_iterator iterator
;
221 _Bit_iterator() : _Bit_iterator_base(0, 0) { }
223 _Bit_iterator(_Bit_type
* __x
, unsigned int __y
)
224 : _Bit_iterator_base(__x
, __y
) { }
228 { return reference(_M_p
, 1UL << _M_offset
); }
240 iterator __tmp
= *this;
255 iterator __tmp
= *this;
261 operator+=(difference_type __i
)
268 operator-=(difference_type __i
)
275 operator+(difference_type __i
) const
277 iterator __tmp
= *this;
282 operator-(difference_type __i
) const
284 iterator __tmp
= *this;
289 operator[](difference_type __i
) const
290 { return *(*this + __i
); }
294 operator+(ptrdiff_t __n
, const _Bit_iterator
& __x
)
295 { return __x
+ __n
; }
297 struct _Bit_const_iterator
: public _Bit_iterator_base
299 typedef bool reference
;
300 typedef bool const_reference
;
301 typedef const bool* pointer
;
302 typedef _Bit_const_iterator const_iterator
;
304 _Bit_const_iterator() : _Bit_iterator_base(0, 0) { }
306 _Bit_const_iterator(_Bit_type
* __x
, unsigned int __y
)
307 : _Bit_iterator_base(__x
, __y
) { }
309 _Bit_const_iterator(const _Bit_iterator
& __x
)
310 : _Bit_iterator_base(__x
._M_p
, __x
._M_offset
) { }
314 { return _Bit_reference(_M_p
, 1UL << _M_offset
); }
326 const_iterator __tmp
= *this;
341 const_iterator __tmp
= *this;
347 operator+=(difference_type __i
)
354 operator-=(difference_type __i
)
361 operator+(difference_type __i
) const
363 const_iterator __tmp
= *this;
368 operator-(difference_type __i
) const
370 const_iterator __tmp
= *this;
375 operator[](difference_type __i
) const
376 { return *(*this + __i
); }
379 inline _Bit_const_iterator
380 operator+(ptrdiff_t __n
, const _Bit_const_iterator
& __x
)
381 { return __x
+ __n
; }
384 __fill_bvector(_Bit_iterator __first
, _Bit_iterator __last
, bool __x
)
386 for (; __first
!= __last
; ++__first
)
391 fill(_Bit_iterator __first
, _Bit_iterator __last
, const bool& __x
)
393 if (__first
._M_p
!= __last
._M_p
)
395 std::fill(__first
._M_p
+ 1, __last
._M_p
, __x
? ~0 : 0);
396 __fill_bvector(__first
, _Bit_iterator(__first
._M_p
+ 1, 0), __x
);
397 __fill_bvector(_Bit_iterator(__last
._M_p
, 0), __last
, __x
);
400 __fill_bvector(__first
, __last
, __x
);
403 template<typename _Alloc
>
406 typedef typename
_Alloc::template rebind
<_Bit_type
>::other
410 : public _Bit_alloc_type
412 _Bit_iterator _M_start
;
413 _Bit_iterator _M_finish
;
414 _Bit_type
* _M_end_of_storage
;
417 : _Bit_alloc_type(), _M_start(), _M_finish(), _M_end_of_storage(0)
420 _Bvector_impl(const _Bit_alloc_type
& __a
)
421 : _Bit_alloc_type(__a
), _M_start(), _M_finish(), _M_end_of_storage(0)
424 #ifdef __GXX_EXPERIMENTAL_CXX0X__
425 _Bvector_impl(_Bit_alloc_type
&& __a
)
426 : _Bit_alloc_type(std::move(__a
)), _M_start(), _M_finish(),
433 typedef _Alloc allocator_type
;
436 _M_get_Bit_allocator() _GLIBCXX_NOEXCEPT
437 { return *static_cast<_Bit_alloc_type
*>(&this->_M_impl
); }
439 const _Bit_alloc_type
&
440 _M_get_Bit_allocator() const _GLIBCXX_NOEXCEPT
441 { return *static_cast<const _Bit_alloc_type
*>(&this->_M_impl
); }
444 get_allocator() const _GLIBCXX_NOEXCEPT
445 { return allocator_type(_M_get_Bit_allocator()); }
450 _Bvector_base(const allocator_type
& __a
)
453 #ifdef __GXX_EXPERIMENTAL_CXX0X__
454 _Bvector_base(_Bvector_base
&& __x
) noexcept
455 : _M_impl(std::move(__x
._M_get_Bit_allocator()))
457 this->_M_impl
._M_start
= __x
._M_impl
._M_start
;
458 this->_M_impl
._M_finish
= __x
._M_impl
._M_finish
;
459 this->_M_impl
._M_end_of_storage
= __x
._M_impl
._M_end_of_storage
;
460 __x
._M_impl
._M_start
= _Bit_iterator();
461 __x
._M_impl
._M_finish
= _Bit_iterator();
462 __x
._M_impl
._M_end_of_storage
= 0;
467 { this->_M_deallocate(); }
470 _Bvector_impl _M_impl
;
473 _M_allocate(size_t __n
)
474 { return _M_impl
.allocate(_S_nword(__n
)); }
479 if (_M_impl
._M_start
._M_p
)
480 _M_impl
.deallocate(_M_impl
._M_start
._M_p
,
481 _M_impl
._M_end_of_storage
- _M_impl
._M_start
._M_p
);
486 { return (__n
+ int(_S_word_bit
) - 1) / int(_S_word_bit
); }
489 _GLIBCXX_END_NAMESPACE_CONTAINER
492 // Declare a partial specialization of vector<T, Alloc>.
493 #include <bits/stl_vector.h>
495 namespace std
_GLIBCXX_VISIBILITY(default)
497 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
500 * @brief A specialization of vector for booleans which offers fixed time
501 * access to individual elements in any order.
505 * @tparam _Alloc Allocator type.
507 * Note that vector<bool> does not actually meet the requirements for being
508 * a container. This is because the reference and pointer types are not
509 * really references and pointers to bool. See DR96 for details. @see
510 * vector for function documentation.
512 * In some terminology a %vector can be described as a dynamic
513 * C-style array, it offers fast and efficient access to individual
514 * elements in any order and saves the user from worrying about
515 * memory and size allocation. Subscripting ( @c [] ) access is
516 * also provided as with C-style arrays.
518 template<typename _Alloc
>
519 class vector
<bool, _Alloc
> : protected _Bvector_base
<_Alloc
>
521 typedef _Bvector_base
<_Alloc
> _Base
;
523 #ifdef __GXX_EXPERIMENTAL_CXX0X__
524 template<typename
> friend class hash
;
528 typedef bool value_type
;
529 typedef size_t size_type
;
530 typedef ptrdiff_t difference_type
;
531 typedef _Bit_reference reference
;
532 typedef bool const_reference
;
533 typedef _Bit_reference
* pointer
;
534 typedef const bool* const_pointer
;
535 typedef _Bit_iterator iterator
;
536 typedef _Bit_const_iterator const_iterator
;
537 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
538 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
539 typedef _Alloc allocator_type
;
541 allocator_type
get_allocator() const
542 { return _Base::get_allocator(); }
545 using _Base::_M_allocate
;
546 using _Base::_M_deallocate
;
547 using _Base::_S_nword
;
548 using _Base::_M_get_Bit_allocator
;
555 vector(const allocator_type
& __a
)
558 #ifdef __GXX_EXPERIMENTAL_CXX0X__
560 vector(size_type __n
, const allocator_type
& __a
= allocator_type())
561 : vector(__n
, false, __a
)
564 vector(size_type __n
, const bool& __value
,
565 const allocator_type
& __a
= allocator_type())
569 std::fill(this->_M_impl
._M_start
._M_p
, this->_M_impl
._M_end_of_storage
,
574 vector(size_type __n
, const bool& __value
= bool(),
575 const allocator_type
& __a
= allocator_type())
579 std::fill(this->_M_impl
._M_start
._M_p
, this->_M_impl
._M_end_of_storage
,
584 vector(const vector
& __x
)
585 : _Base(__x
._M_get_Bit_allocator())
587 _M_initialize(__x
.size());
588 _M_copy_aligned(__x
.begin(), __x
.end(), this->_M_impl
._M_start
);
591 #ifdef __GXX_EXPERIMENTAL_CXX0X__
592 vector(vector
&& __x
) noexcept
593 : _Base(std::move(__x
)) { }
595 vector(initializer_list
<bool> __l
,
596 const allocator_type
& __a
= allocator_type())
599 _M_initialize_range(__l
.begin(), __l
.end(),
600 random_access_iterator_tag());
604 #ifdef __GXX_EXPERIMENTAL_CXX0X__
605 template<typename _InputIterator
,
606 typename
= std::_RequireInputIter
<_InputIterator
>>
607 vector(_InputIterator __first
, _InputIterator __last
,
608 const allocator_type
& __a
= allocator_type())
610 { _M_initialize_dispatch(__first
, __last
, __false_type()); }
612 template<typename _InputIterator
>
613 vector(_InputIterator __first
, _InputIterator __last
,
614 const allocator_type
& __a
= allocator_type())
617 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
618 _M_initialize_dispatch(__first
, __last
, _Integral());
622 ~vector() _GLIBCXX_NOEXCEPT
{ }
625 operator=(const vector
& __x
)
629 if (__x
.size() > capacity())
631 this->_M_deallocate();
632 _M_initialize(__x
.size());
634 this->_M_impl
._M_finish
= _M_copy_aligned(__x
.begin(), __x
.end(),
639 #ifdef __GXX_EXPERIMENTAL_CXX0X__
641 operator=(vector
&& __x
)
651 operator=(initializer_list
<bool> __l
)
653 this->assign (__l
.begin(), __l
.end());
658 // assign(), a generalized assignment member function. Two
659 // versions: one that takes a count, and one that takes a range.
660 // The range version is a member template, so we dispatch on whether
661 // or not the type is an integer.
663 assign(size_type __n
, const bool& __x
)
664 { _M_fill_assign(__n
, __x
); }
666 #ifdef __GXX_EXPERIMENTAL_CXX0X__
667 template<typename _InputIterator
,
668 typename
= std::_RequireInputIter
<_InputIterator
>>
670 assign(_InputIterator __first
, _InputIterator __last
)
671 { _M_assign_dispatch(__first
, __last
, __false_type()); }
673 template<typename _InputIterator
>
675 assign(_InputIterator __first
, _InputIterator __last
)
677 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
678 _M_assign_dispatch(__first
, __last
, _Integral());
682 #ifdef __GXX_EXPERIMENTAL_CXX0X__
684 assign(initializer_list
<bool> __l
)
685 { this->assign(__l
.begin(), __l
.end()); }
689 begin() _GLIBCXX_NOEXCEPT
690 { return this->_M_impl
._M_start
; }
693 begin() const _GLIBCXX_NOEXCEPT
694 { return this->_M_impl
._M_start
; }
697 end() _GLIBCXX_NOEXCEPT
698 { return this->_M_impl
._M_finish
; }
701 end() const _GLIBCXX_NOEXCEPT
702 { return this->_M_impl
._M_finish
; }
705 rbegin() _GLIBCXX_NOEXCEPT
706 { return reverse_iterator(end()); }
708 const_reverse_iterator
709 rbegin() const _GLIBCXX_NOEXCEPT
710 { return const_reverse_iterator(end()); }
713 rend() _GLIBCXX_NOEXCEPT
714 { return reverse_iterator(begin()); }
716 const_reverse_iterator
717 rend() const _GLIBCXX_NOEXCEPT
718 { return const_reverse_iterator(begin()); }
720 #ifdef __GXX_EXPERIMENTAL_CXX0X__
722 cbegin() const noexcept
723 { return this->_M_impl
._M_start
; }
726 cend() const noexcept
727 { return this->_M_impl
._M_finish
; }
729 const_reverse_iterator
730 crbegin() const noexcept
731 { return const_reverse_iterator(end()); }
733 const_reverse_iterator
734 crend() const noexcept
735 { return const_reverse_iterator(begin()); }
739 size() const _GLIBCXX_NOEXCEPT
740 { return size_type(end() - begin()); }
743 max_size() const _GLIBCXX_NOEXCEPT
745 const size_type __isize
=
746 __gnu_cxx::__numeric_traits
<difference_type
>::__max
747 - int(_S_word_bit
) + 1;
748 const size_type __asize
= _M_get_Bit_allocator().max_size();
749 return (__asize
<= __isize
/ int(_S_word_bit
)
750 ? __asize
* int(_S_word_bit
) : __isize
);
754 capacity() const _GLIBCXX_NOEXCEPT
755 { return size_type(const_iterator(this->_M_impl
._M_end_of_storage
, 0)
759 empty() const _GLIBCXX_NOEXCEPT
760 { return begin() == end(); }
763 operator[](size_type __n
)
765 return *iterator(this->_M_impl
._M_start
._M_p
766 + __n
/ int(_S_word_bit
), __n
% int(_S_word_bit
));
770 operator[](size_type __n
) const
772 return *const_iterator(this->_M_impl
._M_start
._M_p
773 + __n
/ int(_S_word_bit
), __n
% int(_S_word_bit
));
778 _M_range_check(size_type __n
) const
780 if (__n
>= this->size())
781 __throw_out_of_range(__N("vector<bool>::_M_range_check"));
787 { _M_range_check(__n
); return (*this)[__n
]; }
790 at(size_type __n
) const
791 { _M_range_check(__n
); return (*this)[__n
]; }
794 reserve(size_type __n
)
796 if (__n
> max_size())
797 __throw_length_error(__N("vector::reserve"));
798 if (capacity() < __n
)
812 { return *(end() - 1); }
816 { return *(end() - 1); }
818 // _GLIBCXX_RESOLVE_LIB_DEFECTS
819 // DR 464. Suggestion for new member functions in standard containers.
820 // N.B. DR 464 says nothing about vector<bool> but we need something
821 // here due to the way we are implementing DR 464 in the debug-mode
824 data() _GLIBCXX_NOEXCEPT
{ }
829 if (this->_M_impl
._M_finish
._M_p
!= this->_M_impl
._M_end_of_storage
)
830 *this->_M_impl
._M_finish
++ = __x
;
832 _M_insert_aux(end(), __x
);
838 std::swap(this->_M_impl
._M_start
, __x
._M_impl
._M_start
);
839 std::swap(this->_M_impl
._M_finish
, __x
._M_impl
._M_finish
);
840 std::swap(this->_M_impl
._M_end_of_storage
,
841 __x
._M_impl
._M_end_of_storage
);
843 // _GLIBCXX_RESOLVE_LIB_DEFECTS
844 // 431. Swapping containers with unequal allocators.
845 std::__alloc_swap
<typename
_Base::_Bit_alloc_type
>::
846 _S_do_it(_M_get_Bit_allocator(), __x
._M_get_Bit_allocator());
849 // [23.2.5]/1, third-to-last entry in synopsis listing
851 swap(reference __x
, reference __y
) _GLIBCXX_NOEXCEPT
859 insert(iterator __position
, const bool& __x
= bool())
861 const difference_type __n
= __position
- begin();
862 if (this->_M_impl
._M_finish
._M_p
!= this->_M_impl
._M_end_of_storage
863 && __position
== end())
864 *this->_M_impl
._M_finish
++ = __x
;
866 _M_insert_aux(__position
, __x
);
867 return begin() + __n
;
870 #ifdef __GXX_EXPERIMENTAL_CXX0X__
871 template<typename _InputIterator
,
872 typename
= std::_RequireInputIter
<_InputIterator
>>
874 insert(iterator __position
,
875 _InputIterator __first
, _InputIterator __last
)
876 { _M_insert_dispatch(__position
, __first
, __last
, __false_type()); }
878 template<typename _InputIterator
>
880 insert(iterator __position
,
881 _InputIterator __first
, _InputIterator __last
)
883 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
884 _M_insert_dispatch(__position
, __first
, __last
, _Integral());
889 insert(iterator __position
, size_type __n
, const bool& __x
)
890 { _M_fill_insert(__position
, __n
, __x
); }
892 #ifdef __GXX_EXPERIMENTAL_CXX0X__
893 void insert(iterator __p
, initializer_list
<bool> __l
)
894 { this->insert(__p
, __l
.begin(), __l
.end()); }
899 { --this->_M_impl
._M_finish
; }
902 erase(iterator __position
)
904 if (__position
+ 1 != end())
905 std::copy(__position
+ 1, end(), __position
);
906 --this->_M_impl
._M_finish
;
911 erase(iterator __first
, iterator __last
)
913 if (__first
!= __last
)
914 _M_erase_at_end(std::copy(__last
, end(), __first
));
919 resize(size_type __new_size
, bool __x
= bool())
921 if (__new_size
< size())
922 _M_erase_at_end(begin() + difference_type(__new_size
));
924 insert(end(), __new_size
- size(), __x
);
927 #ifdef __GXX_EXPERIMENTAL_CXX0X__
930 { _M_shrink_to_fit(); }
934 flip() _GLIBCXX_NOEXCEPT
936 for (_Bit_type
* __p
= this->_M_impl
._M_start
._M_p
;
937 __p
!= this->_M_impl
._M_end_of_storage
; ++__p
)
942 clear() _GLIBCXX_NOEXCEPT
943 { _M_erase_at_end(begin()); }
947 // Precondition: __first._M_offset == 0 && __result._M_offset == 0.
949 _M_copy_aligned(const_iterator __first
, const_iterator __last
,
952 _Bit_type
* __q
= std::copy(__first
._M_p
, __last
._M_p
, __result
._M_p
);
953 return std::copy(const_iterator(__last
._M_p
, 0), __last
,
958 _M_initialize(size_type __n
)
960 _Bit_type
* __q
= this->_M_allocate(__n
);
961 this->_M_impl
._M_end_of_storage
= __q
+ _S_nword(__n
);
962 this->_M_impl
._M_start
= iterator(__q
, 0);
963 this->_M_impl
._M_finish
= this->_M_impl
._M_start
+ difference_type(__n
);
967 _M_reallocate(size_type __n
);
969 #ifdef __GXX_EXPERIMENTAL_CXX0X__
974 // Check whether it's an integral type. If so, it's not an iterator.
976 // _GLIBCXX_RESOLVE_LIB_DEFECTS
977 // 438. Ambiguity in the "do the right thing" clause
978 template<typename _Integer
>
980 _M_initialize_dispatch(_Integer __n
, _Integer __x
, __true_type
)
982 _M_initialize(static_cast<size_type
>(__n
));
983 std::fill(this->_M_impl
._M_start
._M_p
,
984 this->_M_impl
._M_end_of_storage
, __x
? ~0 : 0);
987 template<typename _InputIterator
>
989 _M_initialize_dispatch(_InputIterator __first
, _InputIterator __last
,
991 { _M_initialize_range(__first
, __last
,
992 std::__iterator_category(__first
)); }
994 template<typename _InputIterator
>
996 _M_initialize_range(_InputIterator __first
, _InputIterator __last
,
997 std::input_iterator_tag
)
999 for (; __first
!= __last
; ++__first
)
1000 push_back(*__first
);
1003 template<typename _ForwardIterator
>
1005 _M_initialize_range(_ForwardIterator __first
, _ForwardIterator __last
,
1006 std::forward_iterator_tag
)
1008 const size_type __n
= std::distance(__first
, __last
);
1010 std::copy(__first
, __last
, this->_M_impl
._M_start
);
1013 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1014 // 438. Ambiguity in the "do the right thing" clause
1015 template<typename _Integer
>
1017 _M_assign_dispatch(_Integer __n
, _Integer __val
, __true_type
)
1018 { _M_fill_assign(__n
, __val
); }
1020 template<class _InputIterator
>
1022 _M_assign_dispatch(_InputIterator __first
, _InputIterator __last
,
1024 { _M_assign_aux(__first
, __last
, std::__iterator_category(__first
)); }
1027 _M_fill_assign(size_t __n
, bool __x
)
1031 std::fill(this->_M_impl
._M_start
._M_p
,
1032 this->_M_impl
._M_end_of_storage
, __x
? ~0 : 0);
1033 insert(end(), __n
- size(), __x
);
1037 _M_erase_at_end(begin() + __n
);
1038 std::fill(this->_M_impl
._M_start
._M_p
,
1039 this->_M_impl
._M_end_of_storage
, __x
? ~0 : 0);
1043 template<typename _InputIterator
>
1045 _M_assign_aux(_InputIterator __first
, _InputIterator __last
,
1046 std::input_iterator_tag
)
1048 iterator __cur
= begin();
1049 for (; __first
!= __last
&& __cur
!= end(); ++__cur
, ++__first
)
1051 if (__first
== __last
)
1052 _M_erase_at_end(__cur
);
1054 insert(end(), __first
, __last
);
1057 template<typename _ForwardIterator
>
1059 _M_assign_aux(_ForwardIterator __first
, _ForwardIterator __last
,
1060 std::forward_iterator_tag
)
1062 const size_type __len
= std::distance(__first
, __last
);
1064 _M_erase_at_end(std::copy(__first
, __last
, begin()));
1067 _ForwardIterator __mid
= __first
;
1068 std::advance(__mid
, size());
1069 std::copy(__first
, __mid
, begin());
1070 insert(end(), __mid
, __last
);
1074 // Check whether it's an integral type. If so, it's not an iterator.
1076 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1077 // 438. Ambiguity in the "do the right thing" clause
1078 template<typename _Integer
>
1080 _M_insert_dispatch(iterator __pos
, _Integer __n
, _Integer __x
,
1082 { _M_fill_insert(__pos
, __n
, __x
); }
1084 template<typename _InputIterator
>
1086 _M_insert_dispatch(iterator __pos
,
1087 _InputIterator __first
, _InputIterator __last
,
1089 { _M_insert_range(__pos
, __first
, __last
,
1090 std::__iterator_category(__first
)); }
1093 _M_fill_insert(iterator __position
, size_type __n
, bool __x
);
1095 template<typename _InputIterator
>
1097 _M_insert_range(iterator __pos
, _InputIterator __first
,
1098 _InputIterator __last
, std::input_iterator_tag
)
1100 for (; __first
!= __last
; ++__first
)
1102 __pos
= insert(__pos
, *__first
);
1107 template<typename _ForwardIterator
>
1109 _M_insert_range(iterator __position
, _ForwardIterator __first
,
1110 _ForwardIterator __last
, std::forward_iterator_tag
);
1113 _M_insert_aux(iterator __position
, bool __x
);
1116 _M_check_len(size_type __n
, const char* __s
) const
1118 if (max_size() - size() < __n
)
1119 __throw_length_error(__N(__s
));
1121 const size_type __len
= size() + std::max(size(), __n
);
1122 return (__len
< size() || __len
> max_size()) ? max_size() : __len
;
1126 _M_erase_at_end(iterator __pos
)
1127 { this->_M_impl
._M_finish
= __pos
; }
1130 _GLIBCXX_END_NAMESPACE_CONTAINER
1133 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1135 #include <bits/functional_hash.h>
1137 namespace std
_GLIBCXX_VISIBILITY(default)
1139 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1142 /// std::hash specialization for vector<bool>.
1143 template<typename _Alloc
>
1144 struct hash
<_GLIBCXX_STD_C::vector
<bool, _Alloc
>>
1145 : public __hash_base
<size_t, _GLIBCXX_STD_C::vector
<bool, _Alloc
>>
1148 operator()(const _GLIBCXX_STD_C::vector
<bool, _Alloc
>&) const noexcept
;
1151 _GLIBCXX_END_NAMESPACE_VERSION
1154 #endif // __GXX_EXPERIMENTAL_CXX0X__