2004-04-16 21:04:07 +02:00
|
|
|
// vector<bool> specialization -*- C++ -*-
|
2001-06-27 19:09:53 +02:00
|
|
|
|
2004-01-27 03:58:06 +01:00
|
|
|
// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
|
2001-06-27 19:09:53 +02:00
|
|
|
//
|
|
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
|
// software; you can redistribute it and/or modify it under the
|
|
|
|
// terms of the GNU General Public License as published by the
|
|
|
|
// Free Software Foundation; either version 2, or (at your option)
|
|
|
|
// any later version.
|
|
|
|
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this library; see the file COPYING. If not, write to the Free
|
|
|
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
// USA.
|
|
|
|
|
|
|
|
// As a special exception, you may use this file as part of a free software
|
|
|
|
// library without restriction. Specifically, if other files instantiate
|
|
|
|
// templates or use macros or inline functions from this file, or you compile
|
|
|
|
// this file and link it with other files to produce an executable, this
|
|
|
|
// file does not by itself cause the resulting executable to be covered by
|
|
|
|
// the GNU General Public License. This exception does not however
|
|
|
|
// invalidate any other reasons why the executable file might be covered by
|
|
|
|
// the GNU General Public License.
|
|
|
|
|
2000-10-05 13:27:02 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994
|
|
|
|
* Hewlett-Packard Company
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute and sell this software
|
|
|
|
* and its documentation for any purpose is hereby granted without fee,
|
|
|
|
* provided that the above copyright notice appear in all copies and
|
|
|
|
* that both that copyright notice and this permission notice appear
|
|
|
|
* in supporting documentation. Hewlett-Packard Company makes no
|
|
|
|
* representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1996-1999
|
|
|
|
* Silicon Graphics Computer Systems, Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute and sell this software
|
|
|
|
* and its documentation for any purpose is hereby granted without fee,
|
|
|
|
* provided that the above copyright notice appear in all copies and
|
|
|
|
* that both that copyright notice and this permission notice appear
|
|
|
|
* in supporting documentation. Silicon Graphics makes no
|
|
|
|
* representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
*/
|
|
|
|
|
c_io_stdio.h: Correct grammar in comments.
2001-11-02 Phil Edwards <pme@gcc.gnu.org>
* config/io/c_io_stdio.h: Correct grammar in comments.
* docs/doxygen/Intro.3: Expand "top-level" man page.
* docs/doxygen/doxygroups.cc: New module definitions (comments).
* docs/doxygen/mainpage.doxy: Tweaks.
* docs/doxygen/run_doxygen: Update Doxygen version, massage man pages.
Add @file hooks so that headers are considered to be documented.
* include/bits/basic_ios.h, include/bits/basic_file.h,
include/bits/basic_string.h, include/bits/boost_concept_check.h,
include/bits/char_traits.h, include/bits/codecvt.h,
include/bits/concept_check.h, include/bits/cpp_type_traits.h,
include/bits/fpos.h, include/bits/gslice.h, include/bits/gslice_array.h,
include/bits/indirect_array.h, include/bits/ios_base.h,
include/bits/locale_facets.h, include/bits/localefwd.h,
include/bits/mask_array.h, include/bits/pthread_allocimpl.h,
include/bits/slice.h, include/bits/slice_array.h,
include/bits/std_algorithm.h, include/bits/std_bitset.h,
include/bits/std_complex.h, include/bits/std_deque.h,
include/bits/std_fstream.h, include/bits/std_functional.h,
include/bits/std_iomanip.h, include/bits/std_ios.h,
include/bits/std_iosfwd.h, include/bits/std_iostream.h,
include/bits/std_istream.h, include/bits/std_iterator.h,
include/bits/std_limits.h, include/bits/std_list.h,
include/bits/std_locale.h, include/bits/std_map.h,
include/bits/std_memory.h, include/bits/std_numeric.h,
include/bits/std_ostream.h, include/bits/std_queue.h,
include/bits/std_set.h, include/bits/std_sstream.h,
include/bits/std_stack.h, include/bits/std_streambuf.h,
include/bits/std_string.h, include/bits/std_utility.h,
include/bits/std_valarray.h, include/bits/std_vector.h,
include/bits/stl_algo.h, include/bits/stl_alloc.h,
include/bits/stl_bvector.h, include/bits/stl_construct.h,
include/bits/stl_deque.h, include/bits/stl_heap.h,
include/bits/stl_iterator.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_iterator_base_types.h, include/bits/stl_list.h,
include/bits/stl_map.h, include/bits/stl_multimap.h,
include/bits/stl_multiset.h, include/bits/stl_numeric.h,
include/bits/stl_pair.h, include/bits/stl_pthread_alloc.h,
include/bits/stl_queue.h, include/bits/stl_raw_storage_iter.h,
include/bits/stl_relops.h, include/bits/stl_set.h,
include/bits/stl_stack.h, include/bits/stl_tempbuf.h,
include/bits/stl_threads.h, include/bits/stl_tree.h,
include/bits/stl_uninitialized.h, include/bits/stl_vector.h,
include/bits/stream_iterator.h, include/bits/streambuf_iterator.h,
include/bits/stringfwd.h, include/bits/type_traits.h,
include/bits/valarray_array.h, include/bits/valarray_meta.h:
Add hooks, tweak comments only.
* include/bits/stl_algobase.h (swap, min, iter_swap): Also
document these functions.
* include/bits/stl_function.h: Tweak link comments.
From-SVN: r46717
2001-11-02 18:38:11 +01:00
|
|
|
/** @file stl_bvector.h
|
|
|
|
* This is an internal header file, included by other library headers.
|
|
|
|
* You should not attempt to use it directly.
|
2000-10-05 13:27:02 +02:00
|
|
|
*/
|
|
|
|
|
2003-07-05 06:05:45 +02:00
|
|
|
#ifndef _BVECTOR_H
|
|
|
|
#define _BVECTOR_H 1
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-04-16 21:04:07 +02:00
|
|
|
namespace _GLIBCXX_STD
|
2004-02-08 05:46:42 +01:00
|
|
|
{
|
2002-03-11 23:36:30 +01:00
|
|
|
typedef unsigned long _Bit_type;
|
2003-05-07 07:01:59 +02:00
|
|
|
enum { _S_word_bit = int(CHAR_BIT * sizeof(_Bit_type)) };
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
struct _Bit_reference
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
_Bit_type * _M_p;
|
|
|
|
_Bit_type _M_mask;
|
2002-03-11 23:36:30 +01:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
_Bit_reference(_Bit_type * __x, _Bit_type __y)
|
2004-01-29 01:18:40 +01:00
|
|
|
: _M_p(__x), _M_mask(__y) { }
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
_Bit_reference() : _M_p(0), _M_mask(0) { }
|
|
|
|
|
|
|
|
operator bool() const { return !!(*_M_p & _M_mask); }
|
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
_Bit_reference&
|
2004-01-29 01:18:40 +01:00
|
|
|
operator=(bool __x)
|
|
|
|
{
|
2004-02-08 05:46:42 +01:00
|
|
|
if (__x)
|
2004-01-29 01:18:40 +01:00
|
|
|
*_M_p |= _M_mask;
|
2004-02-08 05:46:42 +01:00
|
|
|
else
|
2004-01-29 01:18:40 +01:00
|
|
|
*_M_p &= ~_M_mask;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
_Bit_reference&
|
|
|
|
operator=(const _Bit_reference& __x)
|
2000-10-05 13:27:02 +02:00
|
|
|
{ return *this = bool(__x); }
|
2004-01-29 01:18:40 +01:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
bool
|
2004-01-29 01:18:40 +01:00
|
|
|
operator==(const _Bit_reference& __x) const
|
2000-10-05 13:27:02 +02:00
|
|
|
{ return bool(*this) == bool(__x); }
|
2004-01-29 01:18:40 +01:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
bool
|
2004-01-29 01:18:40 +01:00
|
|
|
operator<(const _Bit_reference& __x) const
|
2002-03-11 23:36:30 +01:00
|
|
|
{ return !bool(*this) && bool(__x); }
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
void
|
2004-01-29 01:18:40 +01:00
|
|
|
flip() { *_M_p ^= _M_mask; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Bit_iterator_base : public iterator<random_access_iterator_tag, bool>
|
|
|
|
{
|
|
|
|
_Bit_type * _M_p;
|
|
|
|
unsigned int _M_offset;
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
_Bit_iterator_base(_Bit_type * __x, unsigned int __y)
|
|
|
|
: _M_p(__x), _M_offset(__y) { }
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
void
|
|
|
|
_M_bump_up()
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
2004-02-08 05:46:42 +01:00
|
|
|
if (_M_offset++ == _S_word_bit - 1)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
_M_offset = 0;
|
|
|
|
++_M_p;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
2004-01-29 01:18:40 +01:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
void
|
|
|
|
_M_bump_down()
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
2004-02-08 05:46:42 +01:00
|
|
|
if (_M_offset-- == 0)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
_M_offset = _S_word_bit - 1;
|
|
|
|
--_M_p;
|
|
|
|
}
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
_M_incr(ptrdiff_t __i)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
difference_type __n = __i + _M_offset;
|
|
|
|
_M_p += __n / _S_word_bit;
|
|
|
|
__n = __n % _S_word_bit;
|
2004-02-08 05:46:42 +01:00
|
|
|
if (__n < 0)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
_M_offset = static_cast<unsigned int>(__n + _S_word_bit);
|
|
|
|
--_M_p;
|
2004-02-08 05:46:42 +01:00
|
|
|
}
|
2004-01-29 01:18:40 +01:00
|
|
|
else
|
|
|
|
_M_offset = static_cast<unsigned int>(__n);
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const _Bit_iterator_base& __i) const
|
2004-01-29 01:18:40 +01:00
|
|
|
{ return _M_p == __i._M_p && _M_offset == __i._M_offset; }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
operator<(const _Bit_iterator_base& __i) const
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
2004-02-01 12:25:21 +01:00
|
|
|
return _M_p < __i._M_p
|
|
|
|
|| (_M_p == __i._M_p && _M_offset < __i._M_offset);
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
bool
|
|
|
|
operator!=(const _Bit_iterator_base& __i) const
|
2004-01-29 01:18:40 +01:00
|
|
|
{ return !(*this == __i); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
operator>(const _Bit_iterator_base& __i) const
|
2004-01-29 01:18:40 +01:00
|
|
|
{ return __i < *this; }
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
bool
|
|
|
|
operator<=(const _Bit_iterator_base& __i) const
|
2004-01-29 01:18:40 +01:00
|
|
|
{ return !(__i < *this); }
|
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
bool
|
|
|
|
operator>=(const _Bit_iterator_base& __i) const
|
2004-01-29 01:18:40 +01:00
|
|
|
{ return !(*this < __i); }
|
|
|
|
};
|
|
|
|
|
|
|
|
inline ptrdiff_t
|
2004-02-08 05:46:42 +01:00
|
|
|
operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
return _S_word_bit * (__x._M_p - __y._M_p) + __x._M_offset - __y._M_offset;
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
struct _Bit_iterator : public _Bit_iterator_base
|
|
|
|
{
|
|
|
|
typedef _Bit_reference reference;
|
|
|
|
typedef _Bit_reference* pointer;
|
|
|
|
typedef _Bit_iterator iterator;
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
_Bit_iterator() : _Bit_iterator_base(0, 0) { }
|
2004-02-08 05:46:42 +01:00
|
|
|
_Bit_iterator(_Bit_type * __x, unsigned int __y)
|
2004-01-29 01:18:40 +01:00
|
|
|
: _Bit_iterator_base(__x, __y) { }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
reference
|
2004-01-29 01:18:40 +01:00
|
|
|
operator*() const { return reference(_M_p, 1UL << _M_offset); }
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
iterator&
|
|
|
|
operator++()
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
_M_bump_up();
|
|
|
|
return *this;
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
iterator
|
|
|
|
operator++(int)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
iterator __tmp = *this;
|
|
|
|
_M_bump_up();
|
|
|
|
return __tmp;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
iterator&
|
|
|
|
operator--()
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
_M_bump_down();
|
|
|
|
return *this;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
iterator
|
|
|
|
operator--(int)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
iterator __tmp = *this;
|
|
|
|
_M_bump_down();
|
|
|
|
return __tmp;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
iterator&
|
|
|
|
operator+=(difference_type __i)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
_M_incr(__i);
|
|
|
|
return *this;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
iterator&
|
2004-02-08 05:46:42 +01:00
|
|
|
operator-=(difference_type __i)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
*this += -__i;
|
|
|
|
return *this;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
iterator
|
|
|
|
operator+(difference_type __i) const
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
iterator __tmp = *this;
|
|
|
|
return __tmp += __i;
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
iterator
|
|
|
|
operator-(difference_type __i) const
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
iterator __tmp = *this;
|
|
|
|
return __tmp -= __i;
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
reference
|
2004-02-01 12:25:21 +01:00
|
|
|
operator[](difference_type __i)
|
|
|
|
{ return *(*this + __i); }
|
2004-01-29 01:18:40 +01:00
|
|
|
};
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
inline _Bit_iterator
|
2004-01-29 01:18:40 +01:00
|
|
|
operator+(ptrdiff_t __n, const _Bit_iterator& __x) { return __x + __n; }
|
2000-10-05 13:27:02 +02:00
|
|
|
|
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
struct _Bit_const_iterator : public _Bit_iterator_base
|
|
|
|
{
|
|
|
|
typedef bool reference;
|
|
|
|
typedef bool const_reference;
|
|
|
|
typedef const bool* pointer;
|
|
|
|
typedef _Bit_const_iterator const_iterator;
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
_Bit_const_iterator() : _Bit_iterator_base(0, 0) { }
|
2004-02-08 05:46:42 +01:00
|
|
|
_Bit_const_iterator(_Bit_type * __x, unsigned int __y)
|
2004-01-29 01:18:40 +01:00
|
|
|
: _Bit_iterator_base(__x, __y) { }
|
2004-02-08 05:46:42 +01:00
|
|
|
_Bit_const_iterator(const _Bit_iterator& __x)
|
2004-01-29 01:18:40 +01:00
|
|
|
: _Bit_iterator_base(__x._M_p, __x._M_offset) { }
|
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
const_reference
|
|
|
|
operator*() const
|
2004-01-29 01:18:40 +01:00
|
|
|
{ return _Bit_reference(_M_p, 1UL << _M_offset); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
const_iterator&
|
|
|
|
operator++()
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
_M_bump_up();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
const_iterator
|
|
|
|
operator++(int)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
const_iterator __tmp = *this;
|
|
|
|
_M_bump_up();
|
|
|
|
return __tmp;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
const_iterator&
|
|
|
|
operator--()
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
_M_bump_down();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
const_iterator
|
|
|
|
operator--(int)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
const_iterator __tmp = *this;
|
|
|
|
_M_bump_down();
|
|
|
|
return __tmp;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
const_iterator&
|
|
|
|
operator+=(difference_type __i)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
_M_incr(__i);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
const_iterator&
|
|
|
|
operator-=(difference_type __i)
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
*this += -__i;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-04-16 21:04:07 +02:00
|
|
|
const_iterator
|
|
|
|
operator+(difference_type __i) const {
|
2004-01-29 01:18:40 +01:00
|
|
|
const_iterator __tmp = *this;
|
|
|
|
return __tmp += __i;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
const_iterator
|
|
|
|
operator-(difference_type __i) const
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
|
|
|
const_iterator __tmp = *this;
|
|
|
|
return __tmp -= __i;
|
|
|
|
}
|
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
const_reference
|
|
|
|
operator[](difference_type __i)
|
2004-01-29 01:18:40 +01:00
|
|
|
{ return *(*this + __i); }
|
|
|
|
};
|
2004-02-08 05:46:42 +01:00
|
|
|
|
|
|
|
inline _Bit_const_iterator
|
|
|
|
operator+(ptrdiff_t __n, const _Bit_const_iterator& __x)
|
2004-01-29 01:18:40 +01:00
|
|
|
{ return __x + __n; }
|
|
|
|
|
|
|
|
template<class _Alloc>
|
|
|
|
class _Bvector_base
|
|
|
|
{
|
2004-02-01 12:25:21 +01:00
|
|
|
typedef typename _Alloc::template rebind<_Bit_type>::other
|
|
|
|
_Bit_alloc_type;
|
2004-04-16 21:04:07 +02:00
|
|
|
|
|
|
|
struct _Bvector_impl : public _Bit_alloc_type
|
|
|
|
{
|
|
|
|
_Bit_iterator _M_start;
|
|
|
|
_Bit_iterator _M_finish;
|
|
|
|
_Bit_type* _M_end_of_storage;
|
|
|
|
_Bvector_impl(const _Bit_alloc_type& __a)
|
|
|
|
: _Bit_alloc_type(__a), _M_start(), _M_finish(), _M_end_of_storage(0)
|
|
|
|
{ }
|
|
|
|
};
|
2004-01-29 01:18:40 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef _Alloc allocator_type;
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
allocator_type
|
2004-02-08 05:46:42 +01:00
|
|
|
get_allocator() const
|
2004-04-16 21:04:07 +02:00
|
|
|
{ return *static_cast<const _Bit_alloc_type*>(&this->_M_impl); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-04-16 21:04:07 +02:00
|
|
|
_Bvector_base(const allocator_type& __a) : _M_impl(__a) { }
|
2004-01-29 01:18:40 +01:00
|
|
|
|
|
|
|
~_Bvector_base() { this->_M_deallocate(); }
|
|
|
|
|
|
|
|
protected:
|
2004-04-16 21:04:07 +02:00
|
|
|
_Bvector_impl _M_impl;
|
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
_Bit_type*
|
2004-04-16 21:04:07 +02:00
|
|
|
_M_allocate(size_t __n)
|
|
|
|
{ return _M_impl.allocate((__n + _S_word_bit - 1) / _S_word_bit); }
|
2004-01-29 01:18:40 +01:00
|
|
|
|
2004-02-08 05:46:42 +01:00
|
|
|
void
|
|
|
|
_M_deallocate()
|
2004-01-29 01:18:40 +01:00
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
if (_M_impl._M_start._M_p)
|
|
|
|
_M_impl.deallocate(_M_impl._M_start._M_p,
|
|
|
|
_M_impl._M_end_of_storage - _M_impl._M_start._M_p);
|
2004-02-08 05:46:42 +01:00
|
|
|
}
|
2004-01-29 01:18:40 +01:00
|
|
|
};
|
2004-04-16 21:04:07 +02:00
|
|
|
} // namespace std
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
// Declare a partial specialization of vector<T, Alloc>.
|
|
|
|
#include <bits/stl_vector.h>
|
2004-01-29 01:18:40 +01:00
|
|
|
|
2004-04-16 21:04:07 +02:00
|
|
|
namespace _GLIBCXX_STD
|
2000-10-05 13:27:02 +02:00
|
|
|
{
|
2004-01-27 03:58:06 +01:00
|
|
|
/**
|
|
|
|
* @brief A specialization of vector for booleans which offers fixed time
|
|
|
|
* access to individual elements in any order.
|
|
|
|
*
|
|
|
|
* Note that vector<bool> does not actually meet the requirements for being
|
|
|
|
* a container. This is because the reference and pointer types are not
|
|
|
|
* really references and pointers to bool. See DR96 for details. @see
|
|
|
|
* vector for function documentation.
|
|
|
|
*
|
|
|
|
* @ingroup Containers
|
|
|
|
* @ingroup Sequences
|
|
|
|
*
|
2004-01-29 01:18:40 +01:00
|
|
|
* In some terminology a %vector can be described as a dynamic
|
|
|
|
* C-style array, it offers fast and efficient access to individual
|
|
|
|
* elements in any order and saves the user from worrying about
|
|
|
|
* memory and size allocation. Subscripting ( @c [] ) access is
|
|
|
|
* also provided as with C-style arrays.
|
2004-01-27 03:58:06 +01:00
|
|
|
*/
|
2004-02-08 05:46:42 +01:00
|
|
|
template<typename _Alloc>
|
|
|
|
class vector<bool, _Alloc> : public _Bvector_base<_Alloc>
|
2001-03-04 22:34:02 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef bool value_type;
|
|
|
|
typedef size_t size_type;
|
2004-02-08 05:46:42 +01:00
|
|
|
typedef ptrdiff_t difference_type;
|
2001-03-04 22:34:02 +01:00
|
|
|
typedef _Bit_reference reference;
|
|
|
|
typedef bool const_reference;
|
|
|
|
typedef _Bit_reference* pointer;
|
|
|
|
typedef const bool* const_pointer;
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
typedef _Bit_iterator iterator;
|
|
|
|
typedef _Bit_const_iterator const_iterator;
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2002-09-11 01:19:10 +02:00
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
typedef typename _Bvector_base<_Alloc>::allocator_type allocator_type;
|
2004-02-01 12:25:21 +01:00
|
|
|
|
|
|
|
allocator_type get_allocator() const
|
|
|
|
{ return _Bvector_base<_Alloc>::get_allocator(); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
protected:
|
2004-04-16 21:04:07 +02:00
|
|
|
using _Bvector_base<_Alloc>::_M_allocate;
|
2001-03-04 22:34:02 +01:00
|
|
|
using _Bvector_base<_Alloc>::_M_deallocate;
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
protected:
|
2004-02-01 12:25:21 +01:00
|
|
|
void _M_initialize(size_type __n)
|
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
_Bit_type* __q = this->_M_allocate(__n);
|
|
|
|
this->_M_impl._M_end_of_storage = __q
|
|
|
|
+ (__n + _S_word_bit - 1) / _S_word_bit;
|
|
|
|
this->_M_impl._M_start = iterator(__q, 0);
|
|
|
|
this->_M_impl._M_finish = this->_M_start + difference_type(__n);
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
2004-02-01 12:25:21 +01:00
|
|
|
|
|
|
|
void _M_insert_aux(iterator __position, bool __x)
|
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
|
2004-02-01 12:25:21 +01:00
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
std::copy_backward(__position, this->_M_impl._M_finish,
|
|
|
|
this->_M_impl._M_finish + 1);
|
2004-02-01 12:25:21 +01:00
|
|
|
*__position = __x;
|
2004-04-16 21:04:07 +02:00
|
|
|
++this->_M_impl._M_finish;
|
2004-02-01 12:25:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const size_type __len = size() ? 2 * size()
|
|
|
|
: static_cast<size_type>(_S_word_bit);
|
2004-04-16 21:04:07 +02:00
|
|
|
_Bit_type * __q = this->_M_allocate(__len);
|
2004-02-01 12:25:21 +01:00
|
|
|
iterator __i = std::copy(begin(), __position, iterator(__q, 0));
|
|
|
|
*__i++ = __x;
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_finish = std::copy(__position, end(), __i);
|
2004-02-01 12:25:21 +01:00
|
|
|
this->_M_deallocate();
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_end_of_storage = __q + (__len + _S_word_bit - 1)
|
2004-02-01 12:25:21 +01:00
|
|
|
/ _S_word_bit;
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_start = iterator(__q, 0);
|
2004-02-01 12:25:21 +01:00
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _InputIterator>
|
2001-03-04 22:34:02 +01:00
|
|
|
void _M_initialize_range(_InputIterator __first, _InputIterator __last,
|
2004-02-01 12:25:21 +01:00
|
|
|
input_iterator_tag)
|
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_start = iterator();
|
|
|
|
this->_M_impl._M_finish = iterator();
|
|
|
|
this->_M_impl._M_end_of_storage = 0;
|
2004-02-08 05:46:42 +01:00
|
|
|
for ( ; __first != __last; ++__first)
|
2001-03-04 22:34:02 +01:00
|
|
|
push_back(*__first);
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _ForwardIterator>
|
2001-03-04 22:34:02 +01:00
|
|
|
void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
|
2004-02-01 12:25:21 +01:00
|
|
|
forward_iterator_tag)
|
|
|
|
{
|
|
|
|
const size_type __n = std::distance(__first, __last);
|
2001-03-04 22:34:02 +01:00
|
|
|
_M_initialize(__n);
|
2004-04-16 21:04:07 +02:00
|
|
|
std::copy(__first, __last, this->_M_impl._M_start);
|
2001-03-04 22:34:02 +01:00
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _InputIterator>
|
2004-04-16 21:04:07 +02:00
|
|
|
void _M_insert_range(iterator __pos, _InputIterator __first,
|
|
|
|
_InputIterator __last, input_iterator_tag)
|
2004-02-01 12:25:21 +01:00
|
|
|
{
|
|
|
|
for ( ; __first != __last; ++__first)
|
|
|
|
{
|
|
|
|
__pos = insert(__pos, *__first);
|
|
|
|
++__pos;
|
|
|
|
}
|
2001-03-04 22:34:02 +01:00
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _ForwardIterator>
|
2004-04-16 21:04:07 +02:00
|
|
|
void _M_insert_range(iterator __position, _ForwardIterator __first,
|
|
|
|
_ForwardIterator __last, forward_iterator_tag)
|
2004-02-01 12:25:21 +01:00
|
|
|
{
|
|
|
|
if (__first != __last)
|
|
|
|
{
|
|
|
|
size_type __n = std::distance(__first, __last);
|
|
|
|
if (capacity() - size() >= __n)
|
|
|
|
{
|
|
|
|
std::copy_backward(__position, end(),
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_finish + difference_type(__n));
|
2004-02-01 12:25:21 +01:00
|
|
|
std::copy(__first, __last, __position);
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_finish += difference_type(__n);
|
2004-02-01 12:25:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const size_type __len = size() + std::max(size(), __n);
|
2004-04-16 21:04:07 +02:00
|
|
|
_Bit_type * __q = this->_M_allocate(__len);
|
2004-02-01 12:25:21 +01:00
|
|
|
iterator __i = std::copy(begin(), __position, iterator(__q, 0));
|
|
|
|
__i = std::copy(__first, __last, __i);
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_finish = std::copy(__position, end(), __i);
|
2004-02-01 12:25:21 +01:00
|
|
|
this->_M_deallocate();
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_end_of_storage = __q + (__len + _S_word_bit - 1)
|
|
|
|
/ _S_word_bit;
|
|
|
|
this->_M_impl._M_start = iterator(__q, 0);
|
2004-02-01 12:25:21 +01:00
|
|
|
}
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
}
|
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
public:
|
2004-02-01 12:25:21 +01:00
|
|
|
iterator begin()
|
2004-04-16 21:04:07 +02:00
|
|
|
{ return this->_M_impl._M_start; }
|
2004-02-01 12:25:21 +01:00
|
|
|
|
|
|
|
const_iterator begin() const
|
2004-04-16 21:04:07 +02:00
|
|
|
{ return this->_M_impl._M_start; }
|
2004-02-01 12:25:21 +01:00
|
|
|
|
|
|
|
iterator end()
|
2004-04-16 21:04:07 +02:00
|
|
|
{ return this->_M_impl._M_finish; }
|
2004-02-01 12:25:21 +01:00
|
|
|
|
|
|
|
const_iterator end() const
|
2004-04-16 21:04:07 +02:00
|
|
|
{ return this->_M_impl._M_finish; }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
reverse_iterator rbegin()
|
|
|
|
{ return reverse_iterator(end()); }
|
|
|
|
|
|
|
|
const_reverse_iterator rbegin() const
|
|
|
|
{ return const_reverse_iterator(end()); }
|
|
|
|
|
|
|
|
reverse_iterator rend()
|
|
|
|
{ return reverse_iterator(begin()); }
|
|
|
|
|
|
|
|
const_reverse_iterator rend() const
|
|
|
|
{ return const_reverse_iterator(begin()); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
size_type size() const
|
|
|
|
{ return size_type(end() - begin()); }
|
|
|
|
|
|
|
|
size_type max_size() const
|
|
|
|
{ return size_type(-1); }
|
|
|
|
|
|
|
|
size_type capacity() const
|
2004-04-16 21:04:07 +02:00
|
|
|
{ return size_type(const_iterator(this->_M_impl._M_end_of_storage, 0)
|
2004-02-01 12:25:21 +01:00
|
|
|
- begin()); }
|
|
|
|
bool empty() const
|
|
|
|
{ return begin() == end(); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
reference operator[](size_type __n)
|
2004-02-01 12:25:21 +01:00
|
|
|
{ return *(begin() + difference_type(__n)); }
|
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
const_reference operator[](size_type __n) const
|
2004-02-01 12:25:21 +01:00
|
|
|
{ return *(begin() + difference_type(__n)); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
void _M_range_check(size_type __n) const
|
|
|
|
{
|
2001-03-04 22:34:02 +01:00
|
|
|
if (__n >= this->size())
|
2003-04-29 01:05:57 +02:00
|
|
|
__throw_out_of_range(__N("vector<bool>::_M_range_check"));
|
2001-03-04 22:34:02 +01:00
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
reference at(size_type __n)
|
2004-02-01 12:25:21 +01:00
|
|
|
{ _M_range_check(__n); return (*this)[__n]; }
|
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
const_reference at(size_type __n) const
|
2004-02-01 12:25:21 +01:00
|
|
|
{ _M_range_check(__n); return (*this)[__n]; }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
explicit vector(const allocator_type& __a = allocator_type())
|
2004-01-29 01:18:40 +01:00
|
|
|
: _Bvector_base<_Alloc>(__a) { }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-04-16 21:04:07 +02:00
|
|
|
vector(size_type __n, bool __value,
|
2004-02-01 12:25:21 +01:00
|
|
|
const allocator_type& __a = allocator_type())
|
2004-04-16 21:04:07 +02:00
|
|
|
: _Bvector_base<_Alloc>(__a)
|
2001-03-04 22:34:02 +01:00
|
|
|
{
|
|
|
|
_M_initialize(__n);
|
2004-04-16 21:04:07 +02:00
|
|
|
std::fill(this->_M_impl._M_start._M_p, this->_M_impl._M_end_of_storage,
|
|
|
|
__value ? ~0 : 0);
|
2001-03-04 22:34:02 +01:00
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
explicit vector(size_type __n)
|
2004-04-16 21:04:07 +02:00
|
|
|
: _Bvector_base<_Alloc>(allocator_type())
|
2001-03-04 22:34:02 +01:00
|
|
|
{
|
|
|
|
_M_initialize(__n);
|
2004-04-16 21:04:07 +02:00
|
|
|
std::fill(this->_M_impl._M_start._M_p,
|
|
|
|
this->_M_impl._M_end_of_storage, 0);
|
2001-03-04 22:34:02 +01:00
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
vector(const vector& __x) : _Bvector_base<_Alloc>(__x.get_allocator())
|
|
|
|
{
|
2001-03-04 22:34:02 +01:00
|
|
|
_M_initialize(__x.size());
|
2004-04-16 21:04:07 +02:00
|
|
|
std::copy(__x.begin(), __x.end(), this->_M_impl._M_start);
|
2001-03-04 22:34:02 +01:00
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
// Check whether it's an integral type. If so, it's not an iterator.
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _Integer>
|
2004-02-01 12:25:21 +01:00
|
|
|
void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
|
|
|
|
{
|
2001-03-04 22:34:02 +01:00
|
|
|
_M_initialize(__n);
|
2004-04-16 21:04:07 +02:00
|
|
|
std::fill(this->_M_impl._M_start._M_p,
|
|
|
|
this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
|
2001-03-04 22:34:02 +01:00
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _InputIterator>
|
2004-04-16 21:04:07 +02:00
|
|
|
void
|
|
|
|
_M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
|
|
|
|
__false_type)
|
|
|
|
{ _M_initialize_range(__first, __last,
|
|
|
|
std::__iterator_category(__first)); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _InputIterator>
|
2004-04-16 21:04:07 +02:00
|
|
|
vector(_InputIterator __first, _InputIterator __last,
|
|
|
|
const allocator_type& __a = allocator_type())
|
|
|
|
: _Bvector_base<_Alloc>(__a)
|
2001-03-04 22:34:02 +01:00
|
|
|
{
|
|
|
|
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
|
|
|
|
_M_initialize_dispatch(__first, __last, _Integral());
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
~vector() { }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
vector& operator=(const vector& __x)
|
|
|
|
{
|
|
|
|
if (&__x == this)
|
|
|
|
return *this;
|
|
|
|
if (__x.size() > capacity())
|
|
|
|
{
|
|
|
|
this->_M_deallocate();
|
|
|
|
_M_initialize(__x.size());
|
|
|
|
}
|
2003-07-02 12:37:33 +02:00
|
|
|
std::copy(__x.begin(), __x.end(), begin());
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_finish = begin() + difference_type(__x.size());
|
2001-03-04 22:34:02 +01:00
|
|
|
return *this;
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
// assign(), a generalized assignment member function. Two
|
|
|
|
// versions: one that takes a count, and one that takes a range.
|
|
|
|
// The range version is a member template, so we dispatch on whether
|
|
|
|
// or not the type is an integer.
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
void _M_fill_assign(size_t __n, bool __x)
|
|
|
|
{
|
|
|
|
if (__n > size())
|
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
std::fill(this->_M_impl._M_start._M_p,
|
|
|
|
this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
|
2004-02-01 12:25:21 +01:00
|
|
|
insert(end(), __n - size(), __x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
erase(begin() + __n, end());
|
2004-04-16 21:04:07 +02:00
|
|
|
std::fill(this->_M_impl._M_start._M_p,
|
|
|
|
this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
|
2004-02-01 12:25:21 +01:00
|
|
|
}
|
2001-03-04 22:34:02 +01:00
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
void assign(size_t __n, bool __x)
|
|
|
|
{ _M_fill_assign(__n, __x); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _InputIterator>
|
2004-02-01 12:25:21 +01:00
|
|
|
void assign(_InputIterator __first, _InputIterator __last)
|
|
|
|
{
|
2001-03-04 22:34:02 +01:00
|
|
|
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
|
|
|
|
_M_assign_dispatch(__first, __last, _Integral());
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _Integer>
|
2001-03-04 22:34:02 +01:00
|
|
|
void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
|
2004-02-01 12:25:21 +01:00
|
|
|
{ _M_fill_assign((size_t) __n, (bool) __val); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _InputIterator>
|
2004-02-01 12:25:21 +01:00
|
|
|
void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
|
|
|
|
__false_type)
|
|
|
|
{ _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _InputIterator>
|
2001-03-04 22:34:02 +01:00
|
|
|
void _M_assign_aux(_InputIterator __first, _InputIterator __last,
|
2004-02-01 12:25:21 +01:00
|
|
|
input_iterator_tag)
|
|
|
|
{
|
2001-03-04 22:34:02 +01:00
|
|
|
iterator __cur = begin();
|
|
|
|
for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
|
|
|
|
*__cur = *__first;
|
|
|
|
if (__first == __last)
|
|
|
|
erase(__cur, end());
|
|
|
|
else
|
|
|
|
insert(end(), __first, __last);
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _ForwardIterator>
|
2001-03-04 22:34:02 +01:00
|
|
|
void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
|
2004-02-01 12:25:21 +01:00
|
|
|
forward_iterator_tag)
|
|
|
|
{
|
|
|
|
const size_type __len = std::distance(__first, __last);
|
2001-03-04 22:34:02 +01:00
|
|
|
if (__len < size())
|
2003-07-02 12:37:33 +02:00
|
|
|
erase(std::copy(__first, __last, begin()), end());
|
2004-02-01 12:25:21 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_ForwardIterator __mid = __first;
|
|
|
|
std::advance(__mid, size());
|
|
|
|
std::copy(__first, __mid, begin());
|
|
|
|
insert(end(), __mid, __last);
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
}
|
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
void reserve(size_type __n)
|
|
|
|
{
|
2002-11-13 23:15:17 +01:00
|
|
|
if (__n > this->max_size())
|
2003-04-28 23:03:19 +02:00
|
|
|
__throw_length_error(__N("vector::reserve"));
|
2004-02-01 12:25:21 +01:00
|
|
|
if (this->capacity() < __n)
|
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
_Bit_type* __q = this->_M_allocate(__n);
|
|
|
|
this->_M_impl._M_finish = std::copy(begin(), end(),
|
|
|
|
iterator(__q, 0));
|
2004-02-01 12:25:21 +01:00
|
|
|
this->_M_deallocate();
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_start = iterator(__q, 0);
|
|
|
|
this->_M_impl._M_end_of_storage = __q + (__n + _S_word_bit - 1) / _S_word_bit;
|
2004-02-01 12:25:21 +01:00
|
|
|
}
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
reference front()
|
|
|
|
{ return *begin(); }
|
|
|
|
|
|
|
|
const_reference front() const
|
|
|
|
{ return *begin(); }
|
|
|
|
|
|
|
|
reference back()
|
|
|
|
{ return *(end() - 1); }
|
|
|
|
|
|
|
|
const_reference back() const
|
|
|
|
{ return *(end() - 1); }
|
|
|
|
|
|
|
|
void push_back(bool __x)
|
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
|
|
|
|
*this->_M_impl._M_finish++ = __x;
|
2001-03-04 22:34:02 +01:00
|
|
|
else
|
|
|
|
_M_insert_aux(end(), __x);
|
|
|
|
}
|
2004-02-01 12:25:21 +01:00
|
|
|
|
|
|
|
void swap(vector<bool, _Alloc>& __x)
|
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
|
|
|
|
std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
|
|
|
|
std::swap(this->_M_impl._M_end_of_storage,
|
|
|
|
__x._M_impl._M_end_of_storage);
|
2001-03-04 22:34:02 +01:00
|
|
|
}
|
2002-06-03 07:03:50 +02:00
|
|
|
|
|
|
|
// [23.2.5]/1, third-to-last entry in synopsis listing
|
2004-02-01 12:25:21 +01:00
|
|
|
static void swap(reference __x, reference __y)
|
|
|
|
{
|
2002-06-03 07:03:50 +02:00
|
|
|
bool __tmp = __x;
|
|
|
|
__x = __y;
|
|
|
|
__y = __tmp;
|
|
|
|
}
|
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
iterator insert(iterator __position, bool __x = bool())
|
|
|
|
{
|
|
|
|
const difference_type __n = __position - begin();
|
2004-04-16 21:04:07 +02:00
|
|
|
if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage
|
2003-01-16 21:30:50 +01:00
|
|
|
&& __position == end())
|
2004-04-16 21:04:07 +02:00
|
|
|
*this->_M_impl._M_finish++ = __x;
|
2001-03-04 22:34:02 +01:00
|
|
|
else
|
|
|
|
_M_insert_aux(__position, __x);
|
|
|
|
return begin() + __n;
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2001-03-04 22:34:02 +01:00
|
|
|
// Check whether it's an integral type. If so, it's not an iterator.
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _Integer>
|
2001-03-04 22:34:02 +01:00
|
|
|
void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
|
2004-02-01 12:25:21 +01:00
|
|
|
__true_type)
|
|
|
|
{ _M_fill_insert(__pos, __n, __x); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _InputIterator>
|
2001-03-04 22:34:02 +01:00
|
|
|
void _M_insert_dispatch(iterator __pos,
|
|
|
|
_InputIterator __first, _InputIterator __last,
|
2004-02-01 12:25:21 +01:00
|
|
|
__false_type)
|
|
|
|
{ _M_insert_range(__pos, __first, __last,
|
|
|
|
std::__iterator_category(__first)); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<class _InputIterator>
|
2001-03-04 22:34:02 +01:00
|
|
|
void insert(iterator __position,
|
2004-02-01 12:25:21 +01:00
|
|
|
_InputIterator __first, _InputIterator __last)
|
|
|
|
{
|
2001-03-04 22:34:02 +01:00
|
|
|
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
|
|
|
|
_M_insert_dispatch(__position, __first, __last, _Integral());
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
void _M_fill_insert(iterator __position, size_type __n, bool __x)
|
|
|
|
{
|
|
|
|
if (__n == 0)
|
|
|
|
return;
|
|
|
|
if (capacity() - size() >= __n)
|
|
|
|
{
|
|
|
|
std::copy_backward(__position, end(),
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_finish + difference_type(__n));
|
2004-02-01 12:25:21 +01:00
|
|
|
std::fill(__position, __position + difference_type(__n), __x);
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_finish += difference_type(__n);
|
2004-02-01 12:25:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const size_type __len = size() + std::max(size(), __n);
|
2004-04-16 21:04:07 +02:00
|
|
|
_Bit_type * __q = this->_M_allocate(__len);
|
2004-02-01 12:25:21 +01:00
|
|
|
iterator __i = std::copy(begin(), __position, iterator(__q, 0));
|
|
|
|
std::fill_n(__i, __n, __x);
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_finish = std::copy(__position, end(),
|
|
|
|
__i + difference_type(__n));
|
2004-02-01 12:25:21 +01:00
|
|
|
this->_M_deallocate();
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_end_of_storage = __q + (__len + _S_word_bit - 1)
|
|
|
|
/ _S_word_bit;
|
|
|
|
this->_M_impl._M_start = iterator(__q, 0);
|
2004-02-01 12:25:21 +01:00
|
|
|
}
|
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
void insert(iterator __position, size_type __n, bool __x)
|
|
|
|
{ _M_fill_insert(__position, __n, __x); }
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
void pop_back()
|
2004-04-16 21:04:07 +02:00
|
|
|
{ --this->_M_impl._M_finish; }
|
2004-02-01 12:25:21 +01:00
|
|
|
|
|
|
|
iterator erase(iterator __position)
|
|
|
|
{
|
2001-03-04 22:34:02 +01:00
|
|
|
if (__position + 1 != end())
|
2003-07-02 12:37:33 +02:00
|
|
|
std::copy(__position + 1, end(), __position);
|
2004-04-16 21:04:07 +02:00
|
|
|
--this->_M_impl._M_finish;
|
2001-03-04 22:34:02 +01:00
|
|
|
return __position;
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
2004-02-01 12:25:21 +01:00
|
|
|
|
|
|
|
iterator erase(iterator __first, iterator __last)
|
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
this->_M_impl._M_finish = std::copy(__last, end(), __first);
|
2001-03-04 22:34:02 +01:00
|
|
|
return __first;
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
2004-02-01 12:25:21 +01:00
|
|
|
|
|
|
|
void resize(size_type __new_size, bool __x = bool())
|
|
|
|
{
|
2004-02-08 05:46:42 +01:00
|
|
|
if (__new_size < size())
|
2001-03-04 22:34:02 +01:00
|
|
|
erase(begin() + difference_type(__new_size), end());
|
|
|
|
else
|
|
|
|
insert(end(), __new_size - size(), __x);
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
2004-02-01 12:25:21 +01:00
|
|
|
|
|
|
|
void flip()
|
|
|
|
{
|
2004-04-16 21:04:07 +02:00
|
|
|
for (_Bit_type * __p = this->_M_impl._M_start._M_p;
|
|
|
|
__p != this->_M_impl._M_end_of_storage; ++__p)
|
2001-03-04 22:34:02 +01:00
|
|
|
*__p = ~*__p;
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
2004-02-08 05:46:42 +01:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
void clear()
|
|
|
|
{ erase(begin(), end()); }
|
2001-03-04 22:34:02 +01:00
|
|
|
};
|
2004-04-16 21:04:07 +02:00
|
|
|
} // namespace std
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2004-02-01 12:25:21 +01:00
|
|
|
#endif
|