1*404b540aSrobert // vector<bool> specialization -*- C++ -*-
2*404b540aSrobert
3*404b540aSrobert // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
4*404b540aSrobert // Free Software Foundation, Inc.
5*404b540aSrobert //
6*404b540aSrobert // This file is part of the GNU ISO C++ Library. This library is free
7*404b540aSrobert // software; you can redistribute it and/or modify it under the
8*404b540aSrobert // terms of the GNU General Public License as published by the
9*404b540aSrobert // Free Software Foundation; either version 2, or (at your option)
10*404b540aSrobert // any later version.
11*404b540aSrobert
12*404b540aSrobert // This library is distributed in the hope that it will be useful,
13*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of
14*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*404b540aSrobert // GNU General Public License for more details.
16*404b540aSrobert
17*404b540aSrobert // You should have received a copy of the GNU General Public License along
18*404b540aSrobert // with this library; see the file COPYING. If not, write to the Free
19*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20*404b540aSrobert // USA.
21*404b540aSrobert
22*404b540aSrobert // As a special exception, you may use this file as part of a free software
23*404b540aSrobert // library without restriction. Specifically, if other files instantiate
24*404b540aSrobert // templates or use macros or inline functions from this file, or you compile
25*404b540aSrobert // this file and link it with other files to produce an executable, this
26*404b540aSrobert // file does not by itself cause the resulting executable to be covered by
27*404b540aSrobert // the GNU General Public License. This exception does not however
28*404b540aSrobert // invalidate any other reasons why the executable file might be covered by
29*404b540aSrobert // the GNU General Public License.
30*404b540aSrobert
31*404b540aSrobert /*
32*404b540aSrobert *
33*404b540aSrobert * Copyright (c) 1994
34*404b540aSrobert * Hewlett-Packard Company
35*404b540aSrobert *
36*404b540aSrobert * Permission to use, copy, modify, distribute and sell this software
37*404b540aSrobert * and its documentation for any purpose is hereby granted without fee,
38*404b540aSrobert * provided that the above copyright notice appear in all copies and
39*404b540aSrobert * that both that copyright notice and this permission notice appear
40*404b540aSrobert * in supporting documentation. Hewlett-Packard Company makes no
41*404b540aSrobert * representations about the suitability of this software for any
42*404b540aSrobert * purpose. It is provided "as is" without express or implied warranty.
43*404b540aSrobert *
44*404b540aSrobert *
45*404b540aSrobert * Copyright (c) 1996-1999
46*404b540aSrobert * Silicon Graphics Computer Systems, Inc.
47*404b540aSrobert *
48*404b540aSrobert * Permission to use, copy, modify, distribute and sell this software
49*404b540aSrobert * and its documentation for any purpose is hereby granted without fee,
50*404b540aSrobert * provided that the above copyright notice appear in all copies and
51*404b540aSrobert * that both that copyright notice and this permission notice appear
52*404b540aSrobert * in supporting documentation. Silicon Graphics makes no
53*404b540aSrobert * representations about the suitability of this software for any
54*404b540aSrobert * purpose. It is provided "as is" without express or implied warranty.
55*404b540aSrobert */
56*404b540aSrobert
57*404b540aSrobert /** @file stl_bvector.h
58*404b540aSrobert * This is an internal header file, included by other library headers.
59*404b540aSrobert * You should not attempt to use it directly.
60*404b540aSrobert */
61*404b540aSrobert
62*404b540aSrobert #ifndef _BVECTOR_H
63*404b540aSrobert #define _BVECTOR_H 1
64*404b540aSrobert
65*404b540aSrobert _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
66*404b540aSrobert
67*404b540aSrobert typedef unsigned long _Bit_type;
68*404b540aSrobert enum { _S_word_bit = int(CHAR_BIT * sizeof(_Bit_type)) };
69*404b540aSrobert
70*404b540aSrobert struct _Bit_reference
71*404b540aSrobert {
72*404b540aSrobert _Bit_type * _M_p;
73*404b540aSrobert _Bit_type _M_mask;
74*404b540aSrobert
_Bit_reference_Bit_reference75*404b540aSrobert _Bit_reference(_Bit_type * __x, _Bit_type __y)
76*404b540aSrobert : _M_p(__x), _M_mask(__y) { }
77*404b540aSrobert
_Bit_reference_Bit_reference78*404b540aSrobert _Bit_reference() : _M_p(0), _M_mask(0) { }
79*404b540aSrobert
80*404b540aSrobert operator bool() const
81*404b540aSrobert { return !!(*_M_p & _M_mask); }
82*404b540aSrobert
83*404b540aSrobert _Bit_reference&
84*404b540aSrobert operator=(bool __x)
85*404b540aSrobert {
86*404b540aSrobert if (__x)
87*404b540aSrobert *_M_p |= _M_mask;
88*404b540aSrobert else
89*404b540aSrobert *_M_p &= ~_M_mask;
90*404b540aSrobert return *this;
91*404b540aSrobert }
92*404b540aSrobert
93*404b540aSrobert _Bit_reference&
94*404b540aSrobert operator=(const _Bit_reference& __x)
95*404b540aSrobert { return *this = bool(__x); }
96*404b540aSrobert
97*404b540aSrobert bool
98*404b540aSrobert operator==(const _Bit_reference& __x) const
99*404b540aSrobert { return bool(*this) == bool(__x); }
100*404b540aSrobert
101*404b540aSrobert bool
102*404b540aSrobert operator<(const _Bit_reference& __x) const
103*404b540aSrobert { return !bool(*this) && bool(__x); }
104*404b540aSrobert
105*404b540aSrobert void
flip_Bit_reference106*404b540aSrobert flip()
107*404b540aSrobert { *_M_p ^= _M_mask; }
108*404b540aSrobert };
109*404b540aSrobert
110*404b540aSrobert struct _Bit_iterator_base
111*404b540aSrobert : public std::iterator<std::random_access_iterator_tag, bool>
112*404b540aSrobert {
113*404b540aSrobert _Bit_type * _M_p;
114*404b540aSrobert unsigned int _M_offset;
115*404b540aSrobert
_Bit_iterator_base_Bit_iterator_base116*404b540aSrobert _Bit_iterator_base(_Bit_type * __x, unsigned int __y)
117*404b540aSrobert : _M_p(__x), _M_offset(__y) { }
118*404b540aSrobert
119*404b540aSrobert void
_M_bump_up_Bit_iterator_base120*404b540aSrobert _M_bump_up()
121*404b540aSrobert {
122*404b540aSrobert if (_M_offset++ == int(_S_word_bit) - 1)
123*404b540aSrobert {
124*404b540aSrobert _M_offset = 0;
125*404b540aSrobert ++_M_p;
126*404b540aSrobert }
127*404b540aSrobert }
128*404b540aSrobert
129*404b540aSrobert void
_M_bump_down_Bit_iterator_base130*404b540aSrobert _M_bump_down()
131*404b540aSrobert {
132*404b540aSrobert if (_M_offset-- == 0)
133*404b540aSrobert {
134*404b540aSrobert _M_offset = int(_S_word_bit) - 1;
135*404b540aSrobert --_M_p;
136*404b540aSrobert }
137*404b540aSrobert }
138*404b540aSrobert
139*404b540aSrobert void
_M_incr_Bit_iterator_base140*404b540aSrobert _M_incr(ptrdiff_t __i)
141*404b540aSrobert {
142*404b540aSrobert difference_type __n = __i + _M_offset;
143*404b540aSrobert _M_p += __n / int(_S_word_bit);
144*404b540aSrobert __n = __n % int(_S_word_bit);
145*404b540aSrobert if (__n < 0)
146*404b540aSrobert {
147*404b540aSrobert __n += int(_S_word_bit);
148*404b540aSrobert --_M_p;
149*404b540aSrobert }
150*404b540aSrobert _M_offset = static_cast<unsigned int>(__n);
151*404b540aSrobert }
152*404b540aSrobert
153*404b540aSrobert bool
154*404b540aSrobert operator==(const _Bit_iterator_base& __i) const
155*404b540aSrobert { return _M_p == __i._M_p && _M_offset == __i._M_offset; }
156*404b540aSrobert
157*404b540aSrobert bool
158*404b540aSrobert operator<(const _Bit_iterator_base& __i) const
159*404b540aSrobert {
160*404b540aSrobert return _M_p < __i._M_p
161*404b540aSrobert || (_M_p == __i._M_p && _M_offset < __i._M_offset);
162*404b540aSrobert }
163*404b540aSrobert
164*404b540aSrobert bool
165*404b540aSrobert operator!=(const _Bit_iterator_base& __i) const
166*404b540aSrobert { return !(*this == __i); }
167*404b540aSrobert
168*404b540aSrobert bool
169*404b540aSrobert operator>(const _Bit_iterator_base& __i) const
170*404b540aSrobert { return __i < *this; }
171*404b540aSrobert
172*404b540aSrobert bool
173*404b540aSrobert operator<=(const _Bit_iterator_base& __i) const
174*404b540aSrobert { return !(__i < *this); }
175*404b540aSrobert
176*404b540aSrobert bool
177*404b540aSrobert operator>=(const _Bit_iterator_base& __i) const
178*404b540aSrobert { return !(*this < __i); }
179*404b540aSrobert };
180*404b540aSrobert
181*404b540aSrobert inline ptrdiff_t
182*404b540aSrobert operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
183*404b540aSrobert {
184*404b540aSrobert return (int(_S_word_bit) * (__x._M_p - __y._M_p)
185*404b540aSrobert + __x._M_offset - __y._M_offset);
186*404b540aSrobert }
187*404b540aSrobert
188*404b540aSrobert struct _Bit_iterator : public _Bit_iterator_base
189*404b540aSrobert {
190*404b540aSrobert typedef _Bit_reference reference;
191*404b540aSrobert typedef _Bit_reference* pointer;
192*404b540aSrobert typedef _Bit_iterator iterator;
193*404b540aSrobert
_Bit_iterator_Bit_iterator194*404b540aSrobert _Bit_iterator() : _Bit_iterator_base(0, 0) { }
195*404b540aSrobert
_Bit_iterator_Bit_iterator196*404b540aSrobert _Bit_iterator(_Bit_type * __x, unsigned int __y)
197*404b540aSrobert : _Bit_iterator_base(__x, __y) { }
198*404b540aSrobert
199*404b540aSrobert reference
200*404b540aSrobert operator*() const
201*404b540aSrobert { return reference(_M_p, 1UL << _M_offset); }
202*404b540aSrobert
203*404b540aSrobert iterator&
204*404b540aSrobert operator++()
205*404b540aSrobert {
206*404b540aSrobert _M_bump_up();
207*404b540aSrobert return *this;
208*404b540aSrobert }
209*404b540aSrobert
210*404b540aSrobert iterator
211*404b540aSrobert operator++(int)
212*404b540aSrobert {
213*404b540aSrobert iterator __tmp = *this;
214*404b540aSrobert _M_bump_up();
215*404b540aSrobert return __tmp;
216*404b540aSrobert }
217*404b540aSrobert
218*404b540aSrobert iterator&
219*404b540aSrobert operator--()
220*404b540aSrobert {
221*404b540aSrobert _M_bump_down();
222*404b540aSrobert return *this;
223*404b540aSrobert }
224*404b540aSrobert
225*404b540aSrobert iterator
226*404b540aSrobert operator--(int)
227*404b540aSrobert {
228*404b540aSrobert iterator __tmp = *this;
229*404b540aSrobert _M_bump_down();
230*404b540aSrobert return __tmp;
231*404b540aSrobert }
232*404b540aSrobert
233*404b540aSrobert iterator&
234*404b540aSrobert operator+=(difference_type __i)
235*404b540aSrobert {
236*404b540aSrobert _M_incr(__i);
237*404b540aSrobert return *this;
238*404b540aSrobert }
239*404b540aSrobert
240*404b540aSrobert iterator&
241*404b540aSrobert operator-=(difference_type __i)
242*404b540aSrobert {
243*404b540aSrobert *this += -__i;
244*404b540aSrobert return *this;
245*404b540aSrobert }
246*404b540aSrobert
247*404b540aSrobert iterator
248*404b540aSrobert operator+(difference_type __i) const
249*404b540aSrobert {
250*404b540aSrobert iterator __tmp = *this;
251*404b540aSrobert return __tmp += __i;
252*404b540aSrobert }
253*404b540aSrobert
254*404b540aSrobert iterator
255*404b540aSrobert operator-(difference_type __i) const
256*404b540aSrobert {
257*404b540aSrobert iterator __tmp = *this;
258*404b540aSrobert return __tmp -= __i;
259*404b540aSrobert }
260*404b540aSrobert
261*404b540aSrobert reference
262*404b540aSrobert operator[](difference_type __i) const
263*404b540aSrobert { return *(*this + __i); }
264*404b540aSrobert };
265*404b540aSrobert
266*404b540aSrobert inline _Bit_iterator
267*404b540aSrobert operator+(ptrdiff_t __n, const _Bit_iterator& __x)
268*404b540aSrobert { return __x + __n; }
269*404b540aSrobert
270*404b540aSrobert struct _Bit_const_iterator : public _Bit_iterator_base
271*404b540aSrobert {
272*404b540aSrobert typedef bool reference;
273*404b540aSrobert typedef bool const_reference;
274*404b540aSrobert typedef const bool* pointer;
275*404b540aSrobert typedef _Bit_const_iterator const_iterator;
276*404b540aSrobert
_Bit_const_iterator_Bit_const_iterator277*404b540aSrobert _Bit_const_iterator() : _Bit_iterator_base(0, 0) { }
278*404b540aSrobert
_Bit_const_iterator_Bit_const_iterator279*404b540aSrobert _Bit_const_iterator(_Bit_type * __x, unsigned int __y)
280*404b540aSrobert : _Bit_iterator_base(__x, __y) { }
281*404b540aSrobert
_Bit_const_iterator_Bit_const_iterator282*404b540aSrobert _Bit_const_iterator(const _Bit_iterator& __x)
283*404b540aSrobert : _Bit_iterator_base(__x._M_p, __x._M_offset) { }
284*404b540aSrobert
285*404b540aSrobert const_reference
286*404b540aSrobert operator*() const
287*404b540aSrobert { return _Bit_reference(_M_p, 1UL << _M_offset); }
288*404b540aSrobert
289*404b540aSrobert const_iterator&
290*404b540aSrobert operator++()
291*404b540aSrobert {
292*404b540aSrobert _M_bump_up();
293*404b540aSrobert return *this;
294*404b540aSrobert }
295*404b540aSrobert
296*404b540aSrobert const_iterator
297*404b540aSrobert operator++(int)
298*404b540aSrobert {
299*404b540aSrobert const_iterator __tmp = *this;
300*404b540aSrobert _M_bump_up();
301*404b540aSrobert return __tmp;
302*404b540aSrobert }
303*404b540aSrobert
304*404b540aSrobert const_iterator&
305*404b540aSrobert operator--()
306*404b540aSrobert {
307*404b540aSrobert _M_bump_down();
308*404b540aSrobert return *this;
309*404b540aSrobert }
310*404b540aSrobert
311*404b540aSrobert const_iterator
312*404b540aSrobert operator--(int)
313*404b540aSrobert {
314*404b540aSrobert const_iterator __tmp = *this;
315*404b540aSrobert _M_bump_down();
316*404b540aSrobert return __tmp;
317*404b540aSrobert }
318*404b540aSrobert
319*404b540aSrobert const_iterator&
320*404b540aSrobert operator+=(difference_type __i)
321*404b540aSrobert {
322*404b540aSrobert _M_incr(__i);
323*404b540aSrobert return *this;
324*404b540aSrobert }
325*404b540aSrobert
326*404b540aSrobert const_iterator&
327*404b540aSrobert operator-=(difference_type __i)
328*404b540aSrobert {
329*404b540aSrobert *this += -__i;
330*404b540aSrobert return *this;
331*404b540aSrobert }
332*404b540aSrobert
333*404b540aSrobert const_iterator
334*404b540aSrobert operator+(difference_type __i) const
335*404b540aSrobert {
336*404b540aSrobert const_iterator __tmp = *this;
337*404b540aSrobert return __tmp += __i;
338*404b540aSrobert }
339*404b540aSrobert
340*404b540aSrobert const_iterator
341*404b540aSrobert operator-(difference_type __i) const
342*404b540aSrobert {
343*404b540aSrobert const_iterator __tmp = *this;
344*404b540aSrobert return __tmp -= __i;
345*404b540aSrobert }
346*404b540aSrobert
347*404b540aSrobert const_reference
348*404b540aSrobert operator[](difference_type __i) const
349*404b540aSrobert { return *(*this + __i); }
350*404b540aSrobert };
351*404b540aSrobert
352*404b540aSrobert inline _Bit_const_iterator
353*404b540aSrobert operator+(ptrdiff_t __n, const _Bit_const_iterator& __x)
354*404b540aSrobert { return __x + __n; }
355*404b540aSrobert
356*404b540aSrobert inline void
__fill_bvector(_Bit_iterator __first,_Bit_iterator __last,bool __x)357*404b540aSrobert __fill_bvector(_Bit_iterator __first, _Bit_iterator __last, bool __x)
358*404b540aSrobert {
359*404b540aSrobert for (; __first != __last; ++__first)
360*404b540aSrobert *__first = __x;
361*404b540aSrobert }
362*404b540aSrobert
363*404b540aSrobert inline void
fill(_Bit_iterator __first,_Bit_iterator __last,const bool & __x)364*404b540aSrobert fill(_Bit_iterator __first, _Bit_iterator __last, const bool& __x)
365*404b540aSrobert {
366*404b540aSrobert if (__first._M_p != __last._M_p)
367*404b540aSrobert {
368*404b540aSrobert std::fill(__first._M_p + 1, __last._M_p, __x ? ~0 : 0);
369*404b540aSrobert __fill_bvector(__first, _Bit_iterator(__first._M_p + 1, 0), __x);
370*404b540aSrobert __fill_bvector(_Bit_iterator(__last._M_p, 0), __last, __x);
371*404b540aSrobert }
372*404b540aSrobert else
373*404b540aSrobert __fill_bvector(__first, __last, __x);
374*404b540aSrobert }
375*404b540aSrobert
376*404b540aSrobert template<class _Alloc>
377*404b540aSrobert struct _Bvector_base
378*404b540aSrobert {
379*404b540aSrobert typedef typename _Alloc::template rebind<_Bit_type>::other
380*404b540aSrobert _Bit_alloc_type;
381*404b540aSrobert
382*404b540aSrobert struct _Bvector_impl
383*404b540aSrobert : public _Bit_alloc_type
384*404b540aSrobert {
385*404b540aSrobert _Bit_iterator _M_start;
386*404b540aSrobert _Bit_iterator _M_finish;
387*404b540aSrobert _Bit_type* _M_end_of_storage;
_Bvector_impl_Bvector_base::_Bvector_impl388*404b540aSrobert _Bvector_impl(const _Bit_alloc_type& __a)
389*404b540aSrobert : _Bit_alloc_type(__a), _M_start(), _M_finish(), _M_end_of_storage(0)
390*404b540aSrobert { }
391*404b540aSrobert };
392*404b540aSrobert
393*404b540aSrobert public:
394*404b540aSrobert typedef _Alloc allocator_type;
395*404b540aSrobert
396*404b540aSrobert _Bit_alloc_type&
_M_get_Bit_allocator_Bvector_base397*404b540aSrobert _M_get_Bit_allocator()
398*404b540aSrobert { return *static_cast<_Bit_alloc_type*>(&this->_M_impl); }
399*404b540aSrobert
400*404b540aSrobert const _Bit_alloc_type&
_M_get_Bit_allocator_Bvector_base401*404b540aSrobert _M_get_Bit_allocator() const
402*404b540aSrobert { return *static_cast<const _Bit_alloc_type*>(&this->_M_impl); }
403*404b540aSrobert
404*404b540aSrobert allocator_type
get_allocator_Bvector_base405*404b540aSrobert get_allocator() const
406*404b540aSrobert { return allocator_type(_M_get_Bit_allocator()); }
407*404b540aSrobert
_Bvector_base_Bvector_base408*404b540aSrobert _Bvector_base(const allocator_type& __a) : _M_impl(__a) { }
409*404b540aSrobert
~_Bvector_base_Bvector_base410*404b540aSrobert ~_Bvector_base()
411*404b540aSrobert { this->_M_deallocate(); }
412*404b540aSrobert
413*404b540aSrobert protected:
414*404b540aSrobert _Bvector_impl _M_impl;
415*404b540aSrobert
416*404b540aSrobert _Bit_type*
_M_allocate_Bvector_base417*404b540aSrobert _M_allocate(size_t __n)
418*404b540aSrobert { return _M_impl.allocate((__n + int(_S_word_bit) - 1)
419*404b540aSrobert / int(_S_word_bit)); }
420*404b540aSrobert
421*404b540aSrobert void
_M_deallocate_Bvector_base422*404b540aSrobert _M_deallocate()
423*404b540aSrobert {
424*404b540aSrobert if (_M_impl._M_start._M_p)
425*404b540aSrobert _M_impl.deallocate(_M_impl._M_start._M_p,
426*404b540aSrobert _M_impl._M_end_of_storage - _M_impl._M_start._M_p);
427*404b540aSrobert }
428*404b540aSrobert };
429*404b540aSrobert
430*404b540aSrobert _GLIBCXX_END_NESTED_NAMESPACE
431*404b540aSrobert
432*404b540aSrobert // Declare a partial specialization of vector<T, Alloc>.
433*404b540aSrobert #include <bits/stl_vector.h>
434*404b540aSrobert
_GLIBCXX_BEGIN_NESTED_NAMESPACE(std,_GLIBCXX_STD)435*404b540aSrobert _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
436*404b540aSrobert
437*404b540aSrobert /**
438*404b540aSrobert * @brief A specialization of vector for booleans which offers fixed time
439*404b540aSrobert * access to individual elements in any order.
440*404b540aSrobert *
441*404b540aSrobert * Note that vector<bool> does not actually meet the requirements for being
442*404b540aSrobert * a container. This is because the reference and pointer types are not
443*404b540aSrobert * really references and pointers to bool. See DR96 for details. @see
444*404b540aSrobert * vector for function documentation.
445*404b540aSrobert *
446*404b540aSrobert * @ingroup Containers
447*404b540aSrobert * @ingroup Sequences
448*404b540aSrobert *
449*404b540aSrobert * In some terminology a %vector can be described as a dynamic
450*404b540aSrobert * C-style array, it offers fast and efficient access to individual
451*404b540aSrobert * elements in any order and saves the user from worrying about
452*404b540aSrobert * memory and size allocation. Subscripting ( @c [] ) access is
453*404b540aSrobert * also provided as with C-style arrays.
454*404b540aSrobert */
455*404b540aSrobert template<typename _Alloc>
456*404b540aSrobert class vector<bool, _Alloc> : protected _Bvector_base<_Alloc>
457*404b540aSrobert {
458*404b540aSrobert typedef _Bvector_base<_Alloc> _Base;
459*404b540aSrobert
460*404b540aSrobert public:
461*404b540aSrobert typedef bool value_type;
462*404b540aSrobert typedef size_t size_type;
463*404b540aSrobert typedef ptrdiff_t difference_type;
464*404b540aSrobert typedef _Bit_reference reference;
465*404b540aSrobert typedef bool const_reference;
466*404b540aSrobert typedef _Bit_reference* pointer;
467*404b540aSrobert typedef const bool* const_pointer;
468*404b540aSrobert typedef _Bit_iterator iterator;
469*404b540aSrobert typedef _Bit_const_iterator const_iterator;
470*404b540aSrobert typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
471*404b540aSrobert typedef std::reverse_iterator<iterator> reverse_iterator;
472*404b540aSrobert typedef _Alloc allocator_type;
473*404b540aSrobert
474*404b540aSrobert allocator_type get_allocator() const
475*404b540aSrobert { return _Base::get_allocator(); }
476*404b540aSrobert
477*404b540aSrobert protected:
478*404b540aSrobert using _Base::_M_allocate;
479*404b540aSrobert using _Base::_M_deallocate;
480*404b540aSrobert using _Base::_M_get_Bit_allocator;
481*404b540aSrobert
482*404b540aSrobert public:
483*404b540aSrobert explicit
484*404b540aSrobert vector(const allocator_type& __a = allocator_type())
485*404b540aSrobert : _Base(__a) { }
486*404b540aSrobert
487*404b540aSrobert explicit
488*404b540aSrobert vector(size_type __n, const bool& __value = bool(),
489*404b540aSrobert const allocator_type& __a = allocator_type())
490*404b540aSrobert : _Base(__a)
491*404b540aSrobert {
492*404b540aSrobert _M_initialize(__n);
493*404b540aSrobert std::fill(this->_M_impl._M_start._M_p, this->_M_impl._M_end_of_storage,
494*404b540aSrobert __value ? ~0 : 0);
495*404b540aSrobert }
496*404b540aSrobert
497*404b540aSrobert vector(const vector& __x)
498*404b540aSrobert : _Base(__x._M_get_Bit_allocator())
499*404b540aSrobert {
500*404b540aSrobert _M_initialize(__x.size());
501*404b540aSrobert _M_copy_aligned(__x.begin(), __x.end(), this->_M_impl._M_start);
502*404b540aSrobert }
503*404b540aSrobert
504*404b540aSrobert template<class _InputIterator>
505*404b540aSrobert vector(_InputIterator __first, _InputIterator __last,
506*404b540aSrobert const allocator_type& __a = allocator_type())
507*404b540aSrobert : _Base(__a)
508*404b540aSrobert {
509*404b540aSrobert typedef typename std::__is_integer<_InputIterator>::__type _Integral;
510*404b540aSrobert _M_initialize_dispatch(__first, __last, _Integral());
511*404b540aSrobert }
512*404b540aSrobert
513*404b540aSrobert ~vector() { }
514*404b540aSrobert
515*404b540aSrobert vector&
516*404b540aSrobert operator=(const vector& __x)
517*404b540aSrobert {
518*404b540aSrobert if (&__x == this)
519*404b540aSrobert return *this;
520*404b540aSrobert if (__x.size() > capacity())
521*404b540aSrobert {
522*404b540aSrobert this->_M_deallocate();
523*404b540aSrobert _M_initialize(__x.size());
524*404b540aSrobert }
525*404b540aSrobert this->_M_impl._M_finish = _M_copy_aligned(__x.begin(), __x.end(),
526*404b540aSrobert begin());
527*404b540aSrobert return *this;
528*404b540aSrobert }
529*404b540aSrobert
530*404b540aSrobert // assign(), a generalized assignment member function. Two
531*404b540aSrobert // versions: one that takes a count, and one that takes a range.
532*404b540aSrobert // The range version is a member template, so we dispatch on whether
533*404b540aSrobert // or not the type is an integer.
534*404b540aSrobert void
535*404b540aSrobert assign(size_type __n, const bool& __x)
536*404b540aSrobert { _M_fill_assign(__n, __x); }
537*404b540aSrobert
538*404b540aSrobert template<class _InputIterator>
539*404b540aSrobert void
540*404b540aSrobert assign(_InputIterator __first, _InputIterator __last)
541*404b540aSrobert {
542*404b540aSrobert typedef typename std::__is_integer<_InputIterator>::__type _Integral;
543*404b540aSrobert _M_assign_dispatch(__first, __last, _Integral());
544*404b540aSrobert }
545*404b540aSrobert
546*404b540aSrobert iterator
547*404b540aSrobert begin()
548*404b540aSrobert { return this->_M_impl._M_start; }
549*404b540aSrobert
550*404b540aSrobert const_iterator
551*404b540aSrobert begin() const
552*404b540aSrobert { return this->_M_impl._M_start; }
553*404b540aSrobert
554*404b540aSrobert iterator
555*404b540aSrobert end()
556*404b540aSrobert { return this->_M_impl._M_finish; }
557*404b540aSrobert
558*404b540aSrobert const_iterator
559*404b540aSrobert end() const
560*404b540aSrobert { return this->_M_impl._M_finish; }
561*404b540aSrobert
562*404b540aSrobert reverse_iterator
563*404b540aSrobert rbegin()
564*404b540aSrobert { return reverse_iterator(end()); }
565*404b540aSrobert
566*404b540aSrobert const_reverse_iterator
567*404b540aSrobert rbegin() const
568*404b540aSrobert { return const_reverse_iterator(end()); }
569*404b540aSrobert
570*404b540aSrobert reverse_iterator
571*404b540aSrobert rend()
572*404b540aSrobert { return reverse_iterator(begin()); }
573*404b540aSrobert
574*404b540aSrobert const_reverse_iterator
575*404b540aSrobert rend() const
576*404b540aSrobert { return const_reverse_iterator(begin()); }
577*404b540aSrobert
578*404b540aSrobert size_type
579*404b540aSrobert size() const
580*404b540aSrobert { return size_type(end() - begin()); }
581*404b540aSrobert
582*404b540aSrobert size_type
583*404b540aSrobert max_size() const
584*404b540aSrobert {
585*404b540aSrobert const size_type __asize = _M_get_Bit_allocator().max_size();
586*404b540aSrobert return (__asize <= size_type(-1) / int(_S_word_bit) ?
587*404b540aSrobert __asize * int(_S_word_bit) : size_type(-1));
588*404b540aSrobert }
589*404b540aSrobert
590*404b540aSrobert size_type
591*404b540aSrobert capacity() const
592*404b540aSrobert { return size_type(const_iterator(this->_M_impl._M_end_of_storage, 0)
593*404b540aSrobert - begin()); }
594*404b540aSrobert
595*404b540aSrobert bool
596*404b540aSrobert empty() const
597*404b540aSrobert { return begin() == end(); }
598*404b540aSrobert
599*404b540aSrobert reference
600*404b540aSrobert operator[](size_type __n)
601*404b540aSrobert {
602*404b540aSrobert return *iterator(this->_M_impl._M_start._M_p
603*404b540aSrobert + __n / int(_S_word_bit), __n % int(_S_word_bit));
604*404b540aSrobert }
605*404b540aSrobert
606*404b540aSrobert const_reference
607*404b540aSrobert operator[](size_type __n) const
608*404b540aSrobert {
609*404b540aSrobert return *const_iterator(this->_M_impl._M_start._M_p
610*404b540aSrobert + __n / int(_S_word_bit), __n % int(_S_word_bit));
611*404b540aSrobert }
612*404b540aSrobert
613*404b540aSrobert protected:
614*404b540aSrobert void
615*404b540aSrobert _M_range_check(size_type __n) const
616*404b540aSrobert {
617*404b540aSrobert if (__n >= this->size())
618*404b540aSrobert __throw_out_of_range(__N("vector<bool>::_M_range_check"));
619*404b540aSrobert }
620*404b540aSrobert
621*404b540aSrobert public:
622*404b540aSrobert reference
623*404b540aSrobert at(size_type __n)
624*404b540aSrobert { _M_range_check(__n); return (*this)[__n]; }
625*404b540aSrobert
626*404b540aSrobert const_reference
627*404b540aSrobert at(size_type __n) const
628*404b540aSrobert { _M_range_check(__n); return (*this)[__n]; }
629*404b540aSrobert
630*404b540aSrobert void
631*404b540aSrobert reserve(size_type __n)
632*404b540aSrobert {
633*404b540aSrobert if (__n > this->max_size())
634*404b540aSrobert __throw_length_error(__N("vector::reserve"));
635*404b540aSrobert if (this->capacity() < __n)
636*404b540aSrobert {
637*404b540aSrobert _Bit_type* __q = this->_M_allocate(__n);
638*404b540aSrobert this->_M_impl._M_finish = _M_copy_aligned(begin(), end(),
639*404b540aSrobert iterator(__q, 0));
640*404b540aSrobert this->_M_deallocate();
641*404b540aSrobert this->_M_impl._M_start = iterator(__q, 0);
642*404b540aSrobert this->_M_impl._M_end_of_storage = (__q + (__n + int(_S_word_bit) - 1)
643*404b540aSrobert / int(_S_word_bit));
644*404b540aSrobert }
645*404b540aSrobert }
646*404b540aSrobert
647*404b540aSrobert reference
648*404b540aSrobert front()
649*404b540aSrobert { return *begin(); }
650*404b540aSrobert
651*404b540aSrobert const_reference
652*404b540aSrobert front() const
653*404b540aSrobert { return *begin(); }
654*404b540aSrobert
655*404b540aSrobert reference
656*404b540aSrobert back()
657*404b540aSrobert { return *(end() - 1); }
658*404b540aSrobert
659*404b540aSrobert const_reference
660*404b540aSrobert back() const
661*404b540aSrobert { return *(end() - 1); }
662*404b540aSrobert
663*404b540aSrobert // _GLIBCXX_RESOLVE_LIB_DEFECTS
664*404b540aSrobert // DR 464. Suggestion for new member functions in standard containers.
665*404b540aSrobert // N.B. DR 464 says nothing about vector<bool> but we need something
666*404b540aSrobert // here due to the way we are implementing DR 464 in the debug-mode
667*404b540aSrobert // vector class.
668*404b540aSrobert void
669*404b540aSrobert data() { }
670*404b540aSrobert
671*404b540aSrobert void
672*404b540aSrobert push_back(bool __x)
673*404b540aSrobert {
674*404b540aSrobert if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
675*404b540aSrobert *this->_M_impl._M_finish++ = __x;
676*404b540aSrobert else
677*404b540aSrobert _M_insert_aux(end(), __x);
678*404b540aSrobert }
679*404b540aSrobert
680*404b540aSrobert void
681*404b540aSrobert swap(vector<bool, _Alloc>& __x)
682*404b540aSrobert {
683*404b540aSrobert std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
684*404b540aSrobert std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
685*404b540aSrobert std::swap(this->_M_impl._M_end_of_storage,
686*404b540aSrobert __x._M_impl._M_end_of_storage);
687*404b540aSrobert
688*404b540aSrobert // _GLIBCXX_RESOLVE_LIB_DEFECTS
689*404b540aSrobert // 431. Swapping containers with unequal allocators.
690*404b540aSrobert std::__alloc_swap<typename _Base::_Bit_alloc_type>::
691*404b540aSrobert _S_do_it(_M_get_Bit_allocator(), __x._M_get_Bit_allocator());
692*404b540aSrobert }
693*404b540aSrobert
694*404b540aSrobert // [23.2.5]/1, third-to-last entry in synopsis listing
695*404b540aSrobert static void
696*404b540aSrobert swap(reference __x, reference __y)
697*404b540aSrobert {
698*404b540aSrobert bool __tmp = __x;
699*404b540aSrobert __x = __y;
700*404b540aSrobert __y = __tmp;
701*404b540aSrobert }
702*404b540aSrobert
703*404b540aSrobert iterator
704*404b540aSrobert insert(iterator __position, const bool& __x = bool())
705*404b540aSrobert {
706*404b540aSrobert const difference_type __n = __position - begin();
707*404b540aSrobert if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage
708*404b540aSrobert && __position == end())
709*404b540aSrobert *this->_M_impl._M_finish++ = __x;
710*404b540aSrobert else
711*404b540aSrobert _M_insert_aux(__position, __x);
712*404b540aSrobert return begin() + __n;
713*404b540aSrobert }
714*404b540aSrobert
715*404b540aSrobert template<class _InputIterator>
716*404b540aSrobert void
717*404b540aSrobert insert(iterator __position,
718*404b540aSrobert _InputIterator __first, _InputIterator __last)
719*404b540aSrobert {
720*404b540aSrobert typedef typename std::__is_integer<_InputIterator>::__type _Integral;
721*404b540aSrobert _M_insert_dispatch(__position, __first, __last, _Integral());
722*404b540aSrobert }
723*404b540aSrobert
724*404b540aSrobert void
725*404b540aSrobert insert(iterator __position, size_type __n, const bool& __x)
726*404b540aSrobert { _M_fill_insert(__position, __n, __x); }
727*404b540aSrobert
728*404b540aSrobert void
729*404b540aSrobert pop_back()
730*404b540aSrobert { --this->_M_impl._M_finish; }
731*404b540aSrobert
732*404b540aSrobert iterator
733*404b540aSrobert erase(iterator __position)
734*404b540aSrobert {
735*404b540aSrobert if (__position + 1 != end())
736*404b540aSrobert std::copy(__position + 1, end(), __position);
737*404b540aSrobert --this->_M_impl._M_finish;
738*404b540aSrobert return __position;
739*404b540aSrobert }
740*404b540aSrobert
741*404b540aSrobert iterator
742*404b540aSrobert erase(iterator __first, iterator __last)
743*404b540aSrobert {
744*404b540aSrobert _M_erase_at_end(std::copy(__last, end(), __first));
745*404b540aSrobert return __first;
746*404b540aSrobert }
747*404b540aSrobert
748*404b540aSrobert void
749*404b540aSrobert resize(size_type __new_size, bool __x = bool())
750*404b540aSrobert {
751*404b540aSrobert if (__new_size < size())
752*404b540aSrobert _M_erase_at_end(begin() + difference_type(__new_size));
753*404b540aSrobert else
754*404b540aSrobert insert(end(), __new_size - size(), __x);
755*404b540aSrobert }
756*404b540aSrobert
757*404b540aSrobert void
758*404b540aSrobert flip()
759*404b540aSrobert {
760*404b540aSrobert for (_Bit_type * __p = this->_M_impl._M_start._M_p;
761*404b540aSrobert __p != this->_M_impl._M_end_of_storage; ++__p)
762*404b540aSrobert *__p = ~*__p;
763*404b540aSrobert }
764*404b540aSrobert
765*404b540aSrobert void
766*404b540aSrobert clear()
767*404b540aSrobert { _M_erase_at_end(begin()); }
768*404b540aSrobert
769*404b540aSrobert
770*404b540aSrobert protected:
771*404b540aSrobert // Precondition: __first._M_offset == 0 && __result._M_offset == 0.
772*404b540aSrobert iterator
773*404b540aSrobert _M_copy_aligned(const_iterator __first, const_iterator __last,
774*404b540aSrobert iterator __result)
775*404b540aSrobert {
776*404b540aSrobert _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p);
777*404b540aSrobert return std::copy(const_iterator(__last._M_p, 0), __last,
778*404b540aSrobert iterator(__q, 0));
779*404b540aSrobert }
780*404b540aSrobert
781*404b540aSrobert void
782*404b540aSrobert _M_initialize(size_type __n)
783*404b540aSrobert {
784*404b540aSrobert _Bit_type* __q = this->_M_allocate(__n);
785*404b540aSrobert this->_M_impl._M_end_of_storage = (__q
786*404b540aSrobert + ((__n + int(_S_word_bit) - 1)
787*404b540aSrobert / int(_S_word_bit)));
788*404b540aSrobert this->_M_impl._M_start = iterator(__q, 0);
789*404b540aSrobert this->_M_impl._M_finish = this->_M_impl._M_start + difference_type(__n);
790*404b540aSrobert }
791*404b540aSrobert
792*404b540aSrobert // Check whether it's an integral type. If so, it's not an iterator.
793*404b540aSrobert template<class _Integer>
794*404b540aSrobert void
795*404b540aSrobert _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
796*404b540aSrobert {
797*404b540aSrobert _M_initialize(__n);
798*404b540aSrobert std::fill(this->_M_impl._M_start._M_p,
799*404b540aSrobert this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
800*404b540aSrobert }
801*404b540aSrobert
802*404b540aSrobert template<class _InputIterator>
803*404b540aSrobert void
804*404b540aSrobert _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
805*404b540aSrobert __false_type)
806*404b540aSrobert { _M_initialize_range(__first, __last,
807*404b540aSrobert std::__iterator_category(__first)); }
808*404b540aSrobert
809*404b540aSrobert template<class _InputIterator>
810*404b540aSrobert void
811*404b540aSrobert _M_initialize_range(_InputIterator __first, _InputIterator __last,
812*404b540aSrobert std::input_iterator_tag)
813*404b540aSrobert {
814*404b540aSrobert for (; __first != __last; ++__first)
815*404b540aSrobert push_back(*__first);
816*404b540aSrobert }
817*404b540aSrobert
818*404b540aSrobert template<class _ForwardIterator>
819*404b540aSrobert void
820*404b540aSrobert _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
821*404b540aSrobert std::forward_iterator_tag)
822*404b540aSrobert {
823*404b540aSrobert const size_type __n = std::distance(__first, __last);
824*404b540aSrobert _M_initialize(__n);
825*404b540aSrobert std::copy(__first, __last, this->_M_impl._M_start);
826*404b540aSrobert }
827*404b540aSrobert
828*404b540aSrobert template<class _Integer>
829*404b540aSrobert void
830*404b540aSrobert _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
831*404b540aSrobert { _M_fill_assign((size_t) __n, (bool) __val); }
832*404b540aSrobert
833*404b540aSrobert template<class _InputIterator>
834*404b540aSrobert void
835*404b540aSrobert _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
836*404b540aSrobert __false_type)
837*404b540aSrobert { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
838*404b540aSrobert
839*404b540aSrobert void
840*404b540aSrobert _M_fill_assign(size_t __n, bool __x)
841*404b540aSrobert {
842*404b540aSrobert if (__n > size())
843*404b540aSrobert {
844*404b540aSrobert std::fill(this->_M_impl._M_start._M_p,
845*404b540aSrobert this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
846*404b540aSrobert insert(end(), __n - size(), __x);
847*404b540aSrobert }
848*404b540aSrobert else
849*404b540aSrobert {
850*404b540aSrobert _M_erase_at_end(begin() + __n);
851*404b540aSrobert std::fill(this->_M_impl._M_start._M_p,
852*404b540aSrobert this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
853*404b540aSrobert }
854*404b540aSrobert }
855*404b540aSrobert
856*404b540aSrobert template<class _InputIterator>
857*404b540aSrobert void
858*404b540aSrobert _M_assign_aux(_InputIterator __first, _InputIterator __last,
859*404b540aSrobert std::input_iterator_tag)
860*404b540aSrobert {
861*404b540aSrobert iterator __cur = begin();
862*404b540aSrobert for (; __first != __last && __cur != end(); ++__cur, ++__first)
863*404b540aSrobert *__cur = *__first;
864*404b540aSrobert if (__first == __last)
865*404b540aSrobert _M_erase_at_end(__cur);
866*404b540aSrobert else
867*404b540aSrobert insert(end(), __first, __last);
868*404b540aSrobert }
869*404b540aSrobert
870*404b540aSrobert template<class _ForwardIterator>
871*404b540aSrobert void
872*404b540aSrobert _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
873*404b540aSrobert std::forward_iterator_tag)
874*404b540aSrobert {
875*404b540aSrobert const size_type __len = std::distance(__first, __last);
876*404b540aSrobert if (__len < size())
877*404b540aSrobert _M_erase_at_end(std::copy(__first, __last, begin()));
878*404b540aSrobert else
879*404b540aSrobert {
880*404b540aSrobert _ForwardIterator __mid = __first;
881*404b540aSrobert std::advance(__mid, size());
882*404b540aSrobert std::copy(__first, __mid, begin());
883*404b540aSrobert insert(end(), __mid, __last);
884*404b540aSrobert }
885*404b540aSrobert }
886*404b540aSrobert
887*404b540aSrobert // Check whether it's an integral type. If so, it's not an iterator.
888*404b540aSrobert template<class _Integer>
889*404b540aSrobert void
890*404b540aSrobert _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
891*404b540aSrobert __true_type)
892*404b540aSrobert { _M_fill_insert(__pos, __n, __x); }
893*404b540aSrobert
894*404b540aSrobert template<class _InputIterator>
895*404b540aSrobert void
896*404b540aSrobert _M_insert_dispatch(iterator __pos,
897*404b540aSrobert _InputIterator __first, _InputIterator __last,
898*404b540aSrobert __false_type)
899*404b540aSrobert { _M_insert_range(__pos, __first, __last,
900*404b540aSrobert std::__iterator_category(__first)); }
901*404b540aSrobert
902*404b540aSrobert void
903*404b540aSrobert _M_fill_insert(iterator __position, size_type __n, bool __x)
904*404b540aSrobert {
905*404b540aSrobert if (__n == 0)
906*404b540aSrobert return;
907*404b540aSrobert if (capacity() - size() >= __n)
908*404b540aSrobert {
909*404b540aSrobert std::copy_backward(__position, end(),
910*404b540aSrobert this->_M_impl._M_finish + difference_type(__n));
911*404b540aSrobert std::fill(__position, __position + difference_type(__n), __x);
912*404b540aSrobert this->_M_impl._M_finish += difference_type(__n);
913*404b540aSrobert }
914*404b540aSrobert else
915*404b540aSrobert {
916*404b540aSrobert const size_type __len = size() + std::max(size(), __n);
917*404b540aSrobert _Bit_type * __q = this->_M_allocate(__len);
918*404b540aSrobert iterator __i = _M_copy_aligned(begin(), __position,
919*404b540aSrobert iterator(__q, 0));
920*404b540aSrobert std::fill(__i, __i + difference_type(__n), __x);
921*404b540aSrobert this->_M_impl._M_finish = std::copy(__position, end(),
922*404b540aSrobert __i + difference_type(__n));
923*404b540aSrobert this->_M_deallocate();
924*404b540aSrobert this->_M_impl._M_end_of_storage = (__q + ((__len
925*404b540aSrobert + int(_S_word_bit) - 1)
926*404b540aSrobert / int(_S_word_bit)));
927*404b540aSrobert this->_M_impl._M_start = iterator(__q, 0);
928*404b540aSrobert }
929*404b540aSrobert }
930*404b540aSrobert
931*404b540aSrobert template<class _InputIterator>
932*404b540aSrobert void
933*404b540aSrobert _M_insert_range(iterator __pos, _InputIterator __first,
934*404b540aSrobert _InputIterator __last, std::input_iterator_tag)
935*404b540aSrobert {
936*404b540aSrobert for (; __first != __last; ++__first)
937*404b540aSrobert {
938*404b540aSrobert __pos = insert(__pos, *__first);
939*404b540aSrobert ++__pos;
940*404b540aSrobert }
941*404b540aSrobert }
942*404b540aSrobert
943*404b540aSrobert template<class _ForwardIterator>
944*404b540aSrobert void
945*404b540aSrobert _M_insert_range(iterator __position, _ForwardIterator __first,
946*404b540aSrobert _ForwardIterator __last, std::forward_iterator_tag)
947*404b540aSrobert {
948*404b540aSrobert if (__first != __last)
949*404b540aSrobert {
950*404b540aSrobert size_type __n = std::distance(__first, __last);
951*404b540aSrobert if (capacity() - size() >= __n)
952*404b540aSrobert {
953*404b540aSrobert std::copy_backward(__position, end(),
954*404b540aSrobert this->_M_impl._M_finish
955*404b540aSrobert + difference_type(__n));
956*404b540aSrobert std::copy(__first, __last, __position);
957*404b540aSrobert this->_M_impl._M_finish += difference_type(__n);
958*404b540aSrobert }
959*404b540aSrobert else
960*404b540aSrobert {
961*404b540aSrobert const size_type __len = size() + std::max(size(), __n);
962*404b540aSrobert _Bit_type * __q = this->_M_allocate(__len);
963*404b540aSrobert iterator __i = _M_copy_aligned(begin(), __position,
964*404b540aSrobert iterator(__q, 0));
965*404b540aSrobert __i = std::copy(__first, __last, __i);
966*404b540aSrobert this->_M_impl._M_finish = std::copy(__position, end(), __i);
967*404b540aSrobert this->_M_deallocate();
968*404b540aSrobert this->_M_impl._M_end_of_storage = (__q
969*404b540aSrobert + ((__len
970*404b540aSrobert + int(_S_word_bit) - 1)
971*404b540aSrobert / int(_S_word_bit)));
972*404b540aSrobert this->_M_impl._M_start = iterator(__q, 0);
973*404b540aSrobert }
974*404b540aSrobert }
975*404b540aSrobert }
976*404b540aSrobert
977*404b540aSrobert void
978*404b540aSrobert _M_insert_aux(iterator __position, bool __x)
979*404b540aSrobert {
980*404b540aSrobert if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
981*404b540aSrobert {
982*404b540aSrobert std::copy_backward(__position, this->_M_impl._M_finish,
983*404b540aSrobert this->_M_impl._M_finish + 1);
984*404b540aSrobert *__position = __x;
985*404b540aSrobert ++this->_M_impl._M_finish;
986*404b540aSrobert }
987*404b540aSrobert else
988*404b540aSrobert {
989*404b540aSrobert const size_type __len = size() ? 2 * size()
990*404b540aSrobert : static_cast<size_type>(_S_word_bit);
991*404b540aSrobert _Bit_type * __q = this->_M_allocate(__len);
992*404b540aSrobert iterator __i = _M_copy_aligned(begin(), __position,
993*404b540aSrobert iterator(__q, 0));
994*404b540aSrobert *__i++ = __x;
995*404b540aSrobert this->_M_impl._M_finish = std::copy(__position, end(), __i);
996*404b540aSrobert this->_M_deallocate();
997*404b540aSrobert this->_M_impl._M_end_of_storage = (__q + ((__len
998*404b540aSrobert + int(_S_word_bit) - 1)
999*404b540aSrobert / int(_S_word_bit)));
1000*404b540aSrobert this->_M_impl._M_start = iterator(__q, 0);
1001*404b540aSrobert }
1002*404b540aSrobert }
1003*404b540aSrobert
1004*404b540aSrobert void
1005*404b540aSrobert _M_erase_at_end(iterator __pos)
1006*404b540aSrobert { this->_M_impl._M_finish = __pos; }
1007*404b540aSrobert };
1008*404b540aSrobert
1009*404b540aSrobert _GLIBCXX_END_NESTED_NAMESPACE
1010*404b540aSrobert
1011*404b540aSrobert #endif
1012