stl_construct.h (construct): Remove.

2001-07-01  Stephen M. Webb <stephen@bregmasoft.com>

	* include/bits/stl_construct.h (construct): Remove.
      	(destroy): Remove.
      	(__destroy): Replaced by use of iterator_traits.
	* include/bits/stl_deque.h: replaced HP iterator functions with
	iterator_traits.
        (construct): changed to _Construct.
	(destroy): changed to _Destroy.
	* include/bits/stl_tempbuf.h: Same.
	* include/bits/stl_tree.h: Same.
	* include/bits/stl_vector.h: Same.
	* include/backward/iterator.h (construct): moved definition to here.
	(destroy): Same.

From-SVN: r43701
This commit is contained in:
Stephen M. Webb 2001-07-02 19:47:09 +00:00 committed by Benjamin Kosnik
parent becbcf96da
commit 494fff4cea
7 changed files with 341 additions and 267 deletions

View File

@ -1,3 +1,18 @@
2001-07-01 Stephen M. Webb <stephen@bregmasoft.com>
* include/bits/stl_construct.h (construct): Remove.
(destroy): Remove.
(__destroy): Replaced by use of iterator_traits.
* include/bits/stl_deque.h: replaced HP iterator functions with
iterator_traits.
(construct): changed to _Construct.
(destroy): changed to _Destroy.
* include/bits/stl_tempbuf.h: Same.
* include/bits/stl_tree.h: Same.
* include/bits/stl_vector.h: Same.
* include/backward/iterator.h (construct): moved definition to here.
(destroy): Same.
2001-06-29 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/locale_facets.tcc (locale::combine): Clone _Impl.

View File

@ -1,32 +1,3 @@
// Backward-compat support -*- C++ -*-
// Copyright (C) 2001 Free Software Foundation, Inc.
//
// 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.
/*
*
* Copyright (c) 1994
@ -104,8 +75,26 @@ using std::istream_iterator;
using std::ostream_iterator;
// Names from stl_construct.h
using std::construct;
using std::destroy;
template<class _T1, class _T2>
inline void
construct(_T1* __p, const _T2& __value)
{ std::_Construct(__p, __value); }
template<class _T1>
inline void
construct(_T1* __p)
{ std::_Construct(__p); }
template <class _Tp>
inline void
destroy(_Tp* __pointer)
{ std::_Destroy(__pointer); }
template <class _ForwardIterator>
inline void
destroy(_ForwardIterator __first, _ForwardIterator __last)
{ std::_Destroy(__first, __last); }
}
// Names from stl_raw_storage_iter.h
using std::raw_storage_iterator;

View File

@ -60,89 +60,85 @@
#ifndef _CPP_BITS_STL_CONSTRUCT_H
#define _CPP_BITS_STL_CONSTRUCT_H 1
#include <bits/type_traits.h>
#include <new>
namespace std
{
// construct and destroy. These functions are not part of the C++ standard,
// and are provided for backward compatibility with the HP STL. We also
// provide internal names _Construct and _Destroy that can be used within
// the library, so that standard-conforming pieces don't have to rely on
// non-standard extensions.
// Internal names
template <class _T1, class _T2>
inline void _Construct(_T1* __p, const _T2& __value) {
new ((void*) __p) _T1(__value);
}
/**
* Invoke an allocated object's constructor with an initializer.
*
* This function is not part of the C++ standard but is used internally
* within the library.
*/
template <class _T1, class _T2>
inline void
_Construct(_T1* __p, const _T2& __value)
{ new (static_cast<void*>(__p)) _T1(__value); }
template <class _T1>
inline void _Construct(_T1* __p) {
new ((void*) __p) _T1();
}
/**
* Invoke an allocated object's constructor without an initializer.
*
* This function is not part of the C++ standard but is used internally
* within the library.
*/
template <class _T1>
inline void
_Construct(_T1* __p)
{ new (static_cast<void*>(__p)) _T1(); }
template <class _Tp>
inline void _Destroy(_Tp* __pointer) {
__pointer->~_Tp();
}
/**
* Destroy a range of objects with nontrivial destructors.
*
* This is a helper function used only by _Destroy().
*/
template <class _ForwardIterator>
inline void
__destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type)
{ for ( ; __first != __last; ++__first) _Destroy(&*__first); }
/**
* Destroy a range of objects with trivial destructors. Since the destructors
* are trivial, there's nothing to do and hopefully this function will be
* entirely optimized away.
*
* This is a helper function used only by _Destroy().
*/
template <class _ForwardIterator>
inline void
__destroy_aux(_ForwardIterator, _ForwardIterator, __true_type)
{ }
/**
* Destroy the object pointed to by a pointer type.
*
* This function is not part of the C++ standard but is used internally
* within the library.
*/
template <class _Tp>
inline void
_Destroy(_Tp* __pointer)
{ __pointer->~_Tp(); }
template <class _ForwardIterator>
void
__destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type)
{
for ( ; __first != __last; ++__first)
destroy(&*__first);
}
template <class _ForwardIterator>
inline void __destroy_aux(_ForwardIterator, _ForwardIterator, __true_type) {}
template <class _ForwardIterator, class _Tp>
inline void
__destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*)
{
typedef typename __type_traits<_Tp>::has_trivial_destructor
_Trivial_destructor;
__destroy_aux(__first, __last, _Trivial_destructor());
}
template <class _ForwardIterator>
inline void _Destroy(_ForwardIterator __first, _ForwardIterator __last) {
__destroy(__first, __last, __value_type(__first));
}
inline void _Destroy(char*, char*) {}
inline void _Destroy(int*, int*) {}
inline void _Destroy(long*, long*) {}
inline void _Destroy(float*, float*) {}
inline void _Destroy(double*, double*) {}
inline void _Destroy(wchar_t*, wchar_t*) {}
// --------------------------------------------------
// Old names from the HP STL.
template <class _T1, class _T2>
inline void construct(_T1* __p, const _T2& __value) {
_Construct(__p, __value);
}
template <class _T1>
inline void construct(_T1* __p) {
_Construct(__p);
}
template <class _Tp>
inline void destroy(_Tp* __pointer) {
_Destroy(__pointer);
}
template <class _ForwardIterator>
inline void destroy(_ForwardIterator __first, _ForwardIterator __last) {
_Destroy(__first, __last);
}
/**
* Destroy a range of objects. If the value_type of the object has
* a trivial destructor, the compiler should optimize all of this
* away, otherwise the objects' destructors must be invoked.
*
* This function is not part of the C++ standard but is used internally
* within the library.
*/
template <class _ForwardIterator>
inline void
_Destroy(_ForwardIterator __first, _ForwardIterator __last)
{
typedef typename iterator_traits<_ForwardIterator>::value_type
_Value_type;
typedef typename __type_traits<_Value_type>::has_trivial_destructor
_Has_trivial_destructor;
__destroy_aux(__first, __last, _Has_trivial_destructor());
}
} // namespace std
#endif /* _CPP_BITS_STL_CONSTRUCT_H */

View File

@ -479,30 +479,40 @@ public: // Constructor, destructor.
deque(size_type __n, const value_type& __value,
const allocator_type& __a = allocator_type()) : _Base(__a, __n)
{ _M_fill_initialize(__value); }
explicit deque(size_type __n) : _Base(allocator_type(), __n)
{ _M_fill_initialize(value_type()); }
explicit
deque(size_type __n)
: _Base(allocator_type(), __n)
{ _M_fill_initialize(value_type()); }
// Check whether it's an integral type. If so, it's not an iterator.
template <class _InputIterator>
deque(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type()) : _Base(__a) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
template<class _InputIterator>
deque(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type())
: _Base(__a)
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
template <class _Integer>
void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) {
_M_initialize_map(__n);
_M_fill_initialize(__x);
}
template<class _Integer>
void
_M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
{
_M_initialize_map(__n);
_M_fill_initialize(__x);
}
template <class _InputIter>
void _M_initialize_dispatch(_InputIter __first, _InputIter __last,
__false_type) {
_M_range_initialize(__first, __last, __iterator_category(__first));
}
template<class _InputIter>
void
_M_initialize_dispatch(_InputIter __first, _InputIter __last, __false_type)
{
typedef typename iterator_traits<_InputIter>::iterator_category _IterCategory;
_M_range_initialize(__first, __last, _IterCategory());
}
~deque() { destroy(_M_start, _M_finish); }
~deque()
{ _Destroy(_M_start, _M_finish); }
deque& operator= (const deque& __x) {
const size_type __len = size();
@ -542,27 +552,32 @@ public:
}
}
void assign(size_type __n, const _Tp& __val) {
_M_fill_assign(__n, __val);
}
void
assign(size_type __n, const _Tp& __val)
{ _M_fill_assign(__n, __val); }
template <class _InputIterator>
void assign(_InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
template<class _InputIterator>
void
assign(_InputIterator __first, _InputIterator __last)
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
private: // helper functions for assign()
template <class _Integer>
void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
{ _M_fill_assign((size_type) __n, (_Tp) __val); }
template<class _Integer>
void
_M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
{ _M_fill_assign(static_cast<size_type>(__n), static_cast<_Tp>(__val)); }
template <class _InputIterator>
void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
__false_type) {
_M_assign_aux(__first, __last, __iterator_category(__first));
}
template<class _InputIterator>
void
_M_assign_dispatch(_InputIterator __first, _InputIterator __last, __false_type)
{
typedef typename iterator_traits<_InputIterator>::iterator_category _IterCategory;
_M_assign_aux(__first, __last, _IterCategory());
}
template <class _InputIterator>
void _M_assign_aux(_InputIterator __first, _InputIterator __last,
@ -585,36 +600,44 @@ private: // helper functions for assign()
public: // push_* and pop_*
void push_back(const value_type& __t) {
void
push_back(const value_type& __t)
{
if (_M_finish._M_cur != _M_finish._M_last - 1) {
construct(_M_finish._M_cur, __t);
_Construct(_M_finish._M_cur, __t);
++_M_finish._M_cur;
}
else
_M_push_back_aux(__t);
}
void push_back() {
void
push_back()
{
if (_M_finish._M_cur != _M_finish._M_last - 1) {
construct(_M_finish._M_cur);
_Construct(_M_finish._M_cur);
++_M_finish._M_cur;
}
else
_M_push_back_aux();
}
void push_front(const value_type& __t) {
void
push_front(const value_type& __t)
{
if (_M_start._M_cur != _M_start._M_first) {
construct(_M_start._M_cur - 1, __t);
_Construct(_M_start._M_cur - 1, __t);
--_M_start._M_cur;
}
else
_M_push_front_aux(__t);
}
void push_front() {
void
push_front()
{
if (_M_start._M_cur != _M_start._M_first) {
construct(_M_start._M_cur - 1);
_Construct(_M_start._M_cur - 1);
--_M_start._M_cur;
}
else
@ -622,18 +645,22 @@ public: // push_* and pop_*
}
void pop_back() {
void
pop_back()
{
if (_M_finish._M_cur != _M_finish._M_first) {
--_M_finish._M_cur;
destroy(_M_finish._M_cur);
_Destroy(_M_finish._M_cur);
}
else
_M_pop_back_aux();
}
void pop_front() {
void
pop_front()
{
if (_M_start._M_cur != _M_start._M_last - 1) {
destroy(_M_start._M_cur);
_Destroy(_M_start._M_cur);
++_M_start._M_cur;
}
else
@ -642,7 +669,9 @@ public: // push_* and pop_*
public: // Insert
iterator insert(iterator position, const value_type& __x) {
iterator
insert(iterator position, const value_type& __x)
{
if (position._M_cur == _M_start._M_cur) {
push_front(__x);
return _M_start;
@ -658,33 +687,40 @@ public: // Insert
}
}
iterator insert(iterator __position)
{ return insert(__position, value_type()); }
iterator
insert(iterator __position)
{ return insert(__position, value_type()); }
void insert(iterator __pos, size_type __n, const value_type& __x)
{ _M_fill_insert(__pos, __n, __x); }
void
insert(iterator __pos, size_type __n, const value_type& __x)
{ _M_fill_insert(__pos, __n, __x); }
void _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
void
_M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
// Check whether it's an integral type. If so, it's not an iterator.
template <class _InputIterator>
void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_insert_dispatch(__pos, __first, __last, _Integral());
}
template<class _InputIterator>
void
insert(iterator __pos, _InputIterator __first, _InputIterator __last)
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_insert_dispatch(__pos, __first, __last, _Integral());
}
template <class _Integer>
void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
__true_type) {
_M_fill_insert(__pos, (size_type) __n, (value_type) __x);
}
template<class _Integer>
void
_M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x, __true_type)
{ _M_fill_insert(__pos, static_cast<size_type>(__n), static_cast<value_type>(__x)); }
template <class _InputIterator>
void _M_insert_dispatch(iterator __pos,
_InputIterator __first, _InputIterator __last,
__false_type) {
insert(__pos, __first, __last, __iterator_category(__first));
}
template<class _InputIterator>
void
_M_insert_dispatch(iterator __pos,
_InputIterator __first, _InputIterator __last,
__false_type)
{
typedef typename iterator_traits<_InputIterator>::iterator_category _IterCategory;
insert(__pos, __first, __last, _IterCategory());
}
void resize(size_type __new_size, const value_type& __x) {
const size_type __len = size();
@ -847,14 +883,14 @@ deque<_Tp,_Alloc>::erase(iterator __first, iterator __last)
if (static_cast<size_type>(__elems_before) < (size() - __n) / 2) {
copy_backward(_M_start, __first, __last);
iterator __new_start = _M_start + __n;
destroy(_M_start, __new_start);
_Destroy(_M_start, __new_start);
_M_destroy_nodes(__new_start._M_node, _M_start._M_node);
_M_start = __new_start;
}
else {
copy(__last, _M_finish, __first);
iterator __new_finish = _M_finish - __n;
destroy(__new_finish, _M_finish);
_Destroy(__new_finish, _M_finish);
_M_destroy_nodes(__new_finish._M_node + 1, _M_finish._M_node + 1);
_M_finish = __new_finish;
}
@ -868,17 +904,17 @@ void deque<_Tp,_Alloc>::clear()
for (_Map_pointer __node = _M_start._M_node + 1;
__node < _M_finish._M_node;
++__node) {
destroy(*__node, *__node + _S_buffer_size());
_Destroy(*__node, *__node + _S_buffer_size());
_M_deallocate_node(*__node);
}
if (_M_start._M_node != _M_finish._M_node) {
destroy(_M_start._M_cur, _M_start._M_last);
destroy(_M_finish._M_first, _M_finish._M_cur);
_Destroy(_M_start._M_cur, _M_start._M_last);
_Destroy(_M_finish._M_first, _M_finish._M_cur);
_M_deallocate_node(_M_finish._M_first);
}
else
destroy(_M_start._M_cur, _M_finish._M_cur);
_Destroy(_M_start._M_cur, _M_finish._M_cur);
_M_finish = _M_start;
}
@ -893,7 +929,7 @@ void deque<_Tp,_Alloc>::_M_fill_initialize(const value_type& __value) {
uninitialized_fill(*__cur, *__cur + _S_buffer_size(), __value);
uninitialized_fill(_M_finish._M_first, _M_finish._M_cur, __value);
}
__STL_UNWIND(destroy(_M_start, iterator(*__cur, __cur)));
__STL_UNWIND(_Destroy(_M_start, iterator(*__cur, __cur)));
}
template <class _Tp, class _Alloc> template <class _InputIterator>
@ -930,18 +966,19 @@ void deque<_Tp,_Alloc>::_M_range_initialize(_ForwardIterator __first,
}
uninitialized_copy(__first, __last, _M_finish._M_first);
}
__STL_UNWIND(destroy(_M_start, iterator(*__cur_node, __cur_node)));
__STL_UNWIND(_Destroy(_M_start, iterator(*__cur_node, __cur_node)));
}
// Called only if _M_finish._M_cur == _M_finish._M_last - 1.
template <class _Tp, class _Alloc>
void deque<_Tp,_Alloc>::_M_push_back_aux(const value_type& __t)
void
deque<_Tp,_Alloc>::_M_push_back_aux(const value_type& __t)
{
value_type __t_copy = __t;
_M_reserve_map_at_back();
*(_M_finish._M_node + 1) = _M_allocate_node();
__STL_TRY {
construct(_M_finish._M_cur, __t_copy);
_Construct(_M_finish._M_cur, __t_copy);
_M_finish._M_set_node(_M_finish._M_node + 1);
_M_finish._M_cur = _M_finish._M_first;
}
@ -950,12 +987,13 @@ void deque<_Tp,_Alloc>::_M_push_back_aux(const value_type& __t)
// Called only if _M_finish._M_cur == _M_finish._M_last - 1.
template <class _Tp, class _Alloc>
void deque<_Tp,_Alloc>::_M_push_back_aux()
void
deque<_Tp,_Alloc>::_M_push_back_aux()
{
_M_reserve_map_at_back();
*(_M_finish._M_node + 1) = _M_allocate_node();
__STL_TRY {
construct(_M_finish._M_cur);
_Construct(_M_finish._M_cur);
_M_finish._M_set_node(_M_finish._M_node + 1);
_M_finish._M_cur = _M_finish._M_first;
}
@ -964,7 +1002,8 @@ void deque<_Tp,_Alloc>::_M_push_back_aux()
// Called only if _M_start._M_cur == _M_start._M_first.
template <class _Tp, class _Alloc>
void deque<_Tp,_Alloc>::_M_push_front_aux(const value_type& __t)
void
deque<_Tp,_Alloc>::_M_push_front_aux(const value_type& __t)
{
value_type __t_copy = __t;
_M_reserve_map_at_front();
@ -972,21 +1011,22 @@ void deque<_Tp,_Alloc>::_M_push_front_aux(const value_type& __t)
__STL_TRY {
_M_start._M_set_node(_M_start._M_node - 1);
_M_start._M_cur = _M_start._M_last - 1;
construct(_M_start._M_cur, __t_copy);
_Construct(_M_start._M_cur, __t_copy);
}
__STL_UNWIND((++_M_start, _M_deallocate_node(*(_M_start._M_node - 1))));
}
// Called only if _M_start._M_cur == _M_start._M_first.
template <class _Tp, class _Alloc>
void deque<_Tp,_Alloc>::_M_push_front_aux()
void
deque<_Tp,_Alloc>::_M_push_front_aux()
{
_M_reserve_map_at_front();
*(_M_start._M_node - 1) = _M_allocate_node();
__STL_TRY {
_M_start._M_set_node(_M_start._M_node - 1);
_M_start._M_cur = _M_start._M_last - 1;
construct(_M_start._M_cur);
_Construct(_M_start._M_cur);
}
__STL_UNWIND((++_M_start, _M_deallocate_node(*(_M_start._M_node - 1))));
}
@ -998,7 +1038,7 @@ void deque<_Tp,_Alloc>::_M_pop_back_aux()
_M_deallocate_node(_M_finish._M_first);
_M_finish._M_set_node(_M_finish._M_node - 1);
_M_finish._M_cur = _M_finish._M_last - 1;
destroy(_M_finish._M_cur);
_Destroy(_M_finish._M_cur);
}
// Called only if _M_start._M_cur == _M_start._M_last - 1. Note that
@ -1008,7 +1048,7 @@ void deque<_Tp,_Alloc>::_M_pop_back_aux()
template <class _Tp, class _Alloc>
void deque<_Tp,_Alloc>::_M_pop_front_aux()
{
destroy(_M_start._M_cur);
_Destroy(_M_start._M_cur);
_M_deallocate_node(_M_start._M_first);
_M_start._M_set_node(_M_start._M_node + 1);
_M_start._M_cur = _M_start._M_first;

View File

@ -149,7 +149,7 @@ public:
}
~_Temporary_buffer() {
destroy(_M_buffer, _M_buffer + _M_len);
_Destroy(_M_buffer, _M_buffer + _M_len);
free(_M_buffer);
}

View File

@ -552,11 +552,12 @@ protected:
protected:
_Link_type _M_create_node(const value_type& __x)
_Link_type
_M_create_node(const value_type& __x)
{
_Link_type __tmp = _M_get_node();
__STL_TRY {
construct(&__tmp->_M_value_field, __x);
_Construct(&__tmp->_M_value_field, __x);
}
__STL_UNWIND(_M_put_node(__tmp));
return __tmp;
@ -571,9 +572,10 @@ protected:
return __tmp;
}
void destroy_node(_Link_type __p)
void
destroy_node(_Link_type __p)
{
destroy(&__p->_M_value_field);
_Destroy(&__p->_M_value_field);
_M_put_node(__p);
}

View File

@ -236,33 +236,39 @@ public:
// Check whether it's an integral type. If so, it's not an iterator.
template <class _InputIterator>
vector(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type()) : _Base(__a) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_aux(__first, __last, _Integral());
}
vector(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type())
: _Base(__a)
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_aux(__first, __last, _Integral());
}
template <class _Integer>
void _M_initialize_aux(_Integer __n, _Integer __value, __true_type) {
_M_start = _M_allocate(__n);
_M_end_of_storage = _M_start + __n;
_M_finish = uninitialized_fill_n(_M_start, __n, __value);
}
void _M_initialize_aux(_Integer __n, _Integer __value, __true_type)
{
_M_start = _M_allocate(__n);
_M_end_of_storage = _M_start + __n;
_M_finish = uninitialized_fill_n(_M_start, __n, __value);
}
template <class _InputIterator>
void _M_initialize_aux(_InputIterator __first, _InputIterator __last,
__false_type) {
_M_range_initialize(__first, __last, __iterator_category(__first));
}
template<class _InputIterator>
void
_M_initialize_aux(_InputIterator __first, _InputIterator __last, __false_type)
{
typedef typename iterator_traits<_InputIterator>::iterator_category _IterCategoy;
_M_range_initialize(__first, __last, _IterCategory());
}
~vector() { destroy(_M_start, _M_finish); }
~vector()
{ _Destroy(_M_start, _M_finish); }
vector<_Tp, _Alloc>& operator=(const vector<_Tp, _Alloc>& __x);
void reserve(size_type __n) {
if (capacity() < __n) {
const size_type __old_size = size();
pointer __tmp = _M_allocate_and_copy(__n, _M_start, _M_finish);
destroy(_M_start, _M_finish);
_Destroy(_M_start, _M_finish);
_M_deallocate(_M_start, _M_end_of_storage - _M_start);
_M_start = __tmp;
_M_finish = __tmp + __old_size;
@ -278,19 +284,26 @@ public:
void assign(size_type __n, const _Tp& __val) { _M_fill_assign(__n, __val); }
void _M_fill_assign(size_type __n, const _Tp& __val);
template <class _InputIterator>
void assign(_InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
template<class _InputIterator>
void
assign(_InputIterator __first, _InputIterator __last)
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
template <class _Integer>
void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
template<class _Integer>
void
_M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
{ _M_fill_assign((size_type) __n, (_Tp) __val); }
template <class _InputIter>
void _M_assign_dispatch(_InputIter __first, _InputIter __last, __false_type)
{ _M_assign_aux(__first, __last, __iterator_category(__first)); }
template<class _InputIter>
void
_M_assign_dispatch(_InputIter __first, _InputIter __last, __false_type)
{
typedef typename iterator_traits<_InputIter>::iterator_category _IterCategory;
_M_assign_aux(__first, __last, _IterCategory());
}
template <class _InputIterator>
void _M_assign_aux(_InputIterator __first, _InputIterator __last,
@ -305,66 +318,85 @@ public:
reference back() { return *(end() - 1); }
const_reference back() const { return *(end() - 1); }
void push_back(const _Tp& __x) {
void
push_back(const _Tp& __x)
{
if (_M_finish != _M_end_of_storage) {
construct(_M_finish, __x);
_Construct(_M_finish, __x);
++_M_finish;
}
else
_M_insert_aux(end(), __x);
}
void push_back() {
void
push_back()
{
if (_M_finish != _M_end_of_storage) {
construct(_M_finish);
_Construct(_M_finish);
++_M_finish;
}
else
_M_insert_aux(end());
}
void swap(vector<_Tp, _Alloc>& __x) {
void
swap(vector<_Tp, _Alloc>& __x)
{
std::swap(_M_start, __x._M_start);
std::swap(_M_finish, __x._M_finish);
std::swap(_M_end_of_storage, __x._M_end_of_storage);
}
iterator insert(iterator __position, const _Tp& __x) {
iterator
insert(iterator __position, const _Tp& __x)
{
size_type __n = __position - begin();
if (_M_finish != _M_end_of_storage && __position == end()) {
construct(_M_finish, __x);
_Construct(_M_finish, __x);
++_M_finish;
}
else
_M_insert_aux(iterator(__position), __x);
return begin() + __n;
}
iterator insert(iterator __position) {
iterator
insert(iterator __position)
{
size_type __n = __position - begin();
if (_M_finish != _M_end_of_storage && __position == end()) {
construct(_M_finish);
_Construct(_M_finish);
++_M_finish;
}
else
_M_insert_aux(iterator(__position));
return begin() + __n;
}
// Check whether it's an integral type. If so, it's not an iterator.
template <class _InputIterator>
void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_insert_dispatch(__pos, __first, __last, _Integral());
}
template<class _InputIterator>
void
insert(iterator __pos, _InputIterator __first, _InputIterator __last)
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_insert_dispatch(__pos, __first, __last, _Integral());
}
template <class _Integer>
void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
__true_type)
{ _M_fill_insert(__pos, (size_type) __n, (_Tp) __val); }
void
_M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val, __true_type)
{ _M_fill_insert(__pos, static_cast<size_type>(__n), static_cast<_Tp>(__val)); }
template <class _InputIterator>
void _M_insert_dispatch(iterator __pos,
_InputIterator __first, _InputIterator __last,
__false_type) {
_M_range_insert(__pos, __first, __last, __iterator_category(__first));
}
template<class _InputIterator>
void
_M_insert_dispatch(iterator __pos,
_InputIterator __first, _InputIterator __last,
__false_type)
{
typedef typename iterator_traits<_InputIterator>::iterator_category _IterCategory;
_M_range_insert(__pos, __first, __last, _IterCategory());
}
void insert (iterator __pos, size_type __n, const _Tp& __x)
{ _M_fill_insert(__pos, __n, __x); }
@ -373,18 +405,18 @@ public:
void pop_back() {
--_M_finish;
destroy(_M_finish);
_Destroy(_M_finish);
}
iterator erase(iterator __position) {
if (__position + 1 != end())
copy(__position + 1, end(), __position);
--_M_finish;
destroy(_M_finish);
_Destroy(_M_finish);
return __position;
}
iterator erase(iterator __first, iterator __last) {
iterator __i(copy(__last, end(), __first));
destroy(__i, end());
_Destroy(__i, end());
_M_finish = _M_finish - (__last - __first);
return __first;
}
@ -497,14 +529,14 @@ vector<_Tp,_Alloc>::operator=(const vector<_Tp, _Alloc>& __x)
const size_type __xlen = __x.size();
if (__xlen > capacity()) {
pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(), __x.end());
destroy(_M_start, _M_finish);
_Destroy(_M_start, _M_finish);
_M_deallocate(_M_start, _M_end_of_storage - _M_start);
_M_start = __tmp;
_M_end_of_storage = _M_start + __xlen;
}
else if (size() >= __xlen) {
iterator __i(copy(__x.begin(), __x.end(), begin()));
destroy(__i, end());
_Destroy(__i, end());
}
else {
copy(__x.begin(), __x.begin() + size(), _M_start);
@ -551,14 +583,14 @@ vector<_Tp, _Alloc>::_M_assign_aux(_ForwardIter __first, _ForwardIter __last,
if (__len > capacity()) {
pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
destroy(_M_start, _M_finish);
_Destroy(_M_start, _M_finish);
_M_deallocate(_M_start, _M_end_of_storage - _M_start);
_M_start = __tmp;
_M_end_of_storage = _M_finish = _M_start + __len;
}
else if (size() >= __len) {
iterator __new_finish(copy(__first, __last, _M_start));
destroy(__new_finish, end());
_Destroy(__new_finish, end());
_M_finish = __new_finish.base();
}
else {
@ -574,7 +606,7 @@ void
vector<_Tp, _Alloc>::_M_insert_aux(iterator __position, const _Tp& __x)
{
if (_M_finish != _M_end_of_storage) {
construct(_M_finish, *(_M_finish - 1));
_Construct(_M_finish, *(_M_finish - 1));
++_M_finish;
_Tp __x_copy = __x;
copy_backward(__position, iterator(_M_finish - 2), iterator(_M_finish- 1));
@ -588,14 +620,14 @@ vector<_Tp, _Alloc>::_M_insert_aux(iterator __position, const _Tp& __x)
__STL_TRY {
__new_finish = uninitialized_copy(iterator(_M_start), __position,
__new_start);
construct(__new_finish.base(), __x);
_Construct(__new_finish.base(), __x);
++__new_finish;
__new_finish = uninitialized_copy(__position, iterator(_M_finish),
__new_finish);
}
__STL_UNWIND((destroy(__new_start,__new_finish),
__STL_UNWIND((_Destroy(__new_start,__new_finish),
_M_deallocate(__new_start.base(),__len)));
destroy(begin(), end());
_Destroy(begin(), end());
_M_deallocate(_M_start, _M_end_of_storage - _M_start);
_M_start = __new_start.base();
_M_finish = __new_finish.base();
@ -608,7 +640,7 @@ void
vector<_Tp, _Alloc>::_M_insert_aux(iterator __position)
{
if (_M_finish != _M_end_of_storage) {
construct(_M_finish, *(_M_finish - 1));
_Construct(_M_finish, *(_M_finish - 1));
++_M_finish;
copy_backward(__position, iterator(_M_finish - 2),
iterator(_M_finish - 1));
@ -622,14 +654,14 @@ vector<_Tp, _Alloc>::_M_insert_aux(iterator __position)
__STL_TRY {
__new_finish = uninitialized_copy(iterator(_M_start), __position,
__new_start);
construct(__new_finish);
_Construct(__new_finish);
++__new_finish;
__new_finish = uninitialized_copy(__position, iterator(_M_finish),
__new_finish);
}
__STL_UNWIND((destroy(__new_start,__new_finish),
__STL_UNWIND((_Destroy(__new_start,__new_finish),
_M_deallocate(__new_start,__len)));
destroy(begin(), end());
_Destroy(begin(), end());
_M_deallocate(_M_start, _M_end_of_storage - _M_start);
_M_start = __new_start;
_M_finish = __new_finish;
@ -671,9 +703,9 @@ void vector<_Tp, _Alloc>::_M_fill_insert(iterator __position, size_type __n,
__new_finish
= uninitialized_copy(__position, end(), __new_finish);
}
__STL_UNWIND((destroy(__new_start,__new_finish),
__STL_UNWIND((_Destroy(__new_start,__new_finish),
_M_deallocate(__new_start.base(),__len)));
destroy(_M_start, _M_finish);
_Destroy(_M_start, _M_finish);
_M_deallocate(_M_start, _M_end_of_storage - _M_start);
_M_start = __new_start.base();
_M_finish = __new_finish.base();
@ -736,9 +768,9 @@ vector<_Tp, _Alloc>::_M_range_insert(iterator __position,
__new_finish
= uninitialized_copy(__position, iterator(_M_finish), __new_finish);
}
__STL_UNWIND((destroy(__new_start,__new_finish),
__STL_UNWIND((_Destroy(__new_start,__new_finish),
_M_deallocate(__new_start.base(),__len)));
destroy(_M_start, _M_finish);
_Destroy(_M_start, _M_finish);
_M_deallocate(_M_start, _M_end_of_storage - _M_start);
_M_start = __new_start.base();
_M_finish = __new_finish.base();