_vector.h revision 9720d5f59b9c1f5d1b9ecbc9173dbcb71bd557be
1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/* 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (c) 1994 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Hewlett-Packard Company 5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (c) 1996,1997 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Silicon Graphics Computer Systems, Inc. 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * Copyright (c) 1997 107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) * Moscow Center for SPARC Technology 117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) * 127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) * Copyright (c) 1999 137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) * Boris Fomitchev 147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) * 15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * This material is provided "as is", with absolutely no warranty expressed 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * or implied. Any use is at your own risk. 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * 18f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * Permission to use or copy this software for any purpose is hereby granted 19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * without fee, provided the above notices are retained on all copies. 20eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * Permission to modify the code and to distribute modified code is granted, 21eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * provided the above notices are retained, and a notice that the code was 22eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * modified is included with the above copyright notice. 23a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch * 24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) */ 25eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)/* NOTE: This is an internal header file, included by other STL headers. 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * You should not attempt to use it directly. 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 29f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef _STLP_INTERNAL_VECTOR_H 31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define _STLP_INTERNAL_VECTOR_H 32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef _STLP_INTERNAL_ALGOBASE_H 34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)# include <stl/_algobase.h> 35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef _STLP_INTERNAL_ALLOC_H 38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)# include <stl/_alloc.h> 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef _STLP_INTERNAL_ITERATOR_H 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# include <stl/_iterator.h> 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef _STLP_INTERNAL_UNINITIALIZED_H 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# include <stl/_uninitialized.h> 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)_STLP_BEGIN_NAMESPACE 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The vector base class serves one purpose, its constructor and 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// destructor allocate (but don't initialize) storage. This makes 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// exception safety easier. 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)_STLP_MOVE_TO_PRIV_NAMESPACE 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)template <class _Tp, class _Alloc> 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class _Vector_base { 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public: 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef _Vector_base<_Tp, _Alloc> _Self; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _STLP_FORCE_ALLOCATORS(_Tp, _Alloc) 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef typename _Alloc_traits<_Tp, _Alloc>::allocator_type allocator_type; 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef _Tp* pointer; 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef _STLP_alloc_proxy<pointer, _Tp, allocator_type> _AllocProxy; 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) _Vector_base(const _Alloc& __a) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : _M_start(0), _M_finish(0), _M_end_of_storage(__a, 0) {} 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _Vector_base(size_t __n, const _Alloc& __a) 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : _M_start(0), _M_finish(0), _M_end_of_storage(__a, 0) { 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _M_start = _M_end_of_storage.allocate(__n, __n); 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _M_finish = _M_start; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _M_end_of_storage._M_data = _M_start + __n; 74cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) _STLP_MPWFIX_TRY _STLP_MPWFIX_CATCH 75cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _Vector_base(__move_source<_Self> src) 78cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) : _M_start(src.get()._M_start), _M_finish(src.get()._M_finish), 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _M_end_of_storage(__move_source<_AllocProxy>(src.get()._M_end_of_storage)) { 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) //Set the source as empty: 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) src.get()._M_finish = src.get()._M_end_of_storage._M_data = src.get()._M_start = 0; 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~_Vector_base() { 85f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (_M_start != _STLP_DEFAULT_CONSTRUCTED(pointer)) 86f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) _M_end_of_storage.deallocate(_M_start, _M_end_of_storage._M_data - _M_start); 87f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 88f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 89f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)protected: 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void _STLP_FUNCTION_THROWS _M_throw_length_error() const; 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void _STLP_FUNCTION_THROWS _M_throw_out_of_range() const; 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pointer _M_start; 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pointer _M_finish; 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _AllocProxy _M_end_of_storage; 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined (_STLP_USE_PTR_SPECIALIZATIONS) 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define vector _STLP_PTR_IMPL_NAME(vector) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined (_STLP_DEBUG) 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define vector _STLP_NON_DBG_NAME(vector) 102f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#else 103f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)_STLP_MOVE_TO_STD_NAMESPACE 104f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#endif 105f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 106f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) > 107f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class vector : protected _STLP_PRIV _Vector_base<_Tp, _Alloc> 108f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (vector) 109f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) , public __stlport_class<vector<_Tp, _Alloc> > 110f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#endif 111f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles){ 112f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)private: 113f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) typedef _STLP_PRIV _Vector_base<_Tp, _Alloc> _Base; 114f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) typedef vector<_Tp, _Alloc> _Self; 115f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)public: 116f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) _STLP_FORCE_ALLOCATORS(_Tp, _Alloc) 117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) typedef typename _Base::allocator_type allocator_type; 118f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef _Tp value_type; 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef value_type* pointer; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef const value_type* const_pointer; 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef value_type* iterator; 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef const value_type* const_iterator; 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef value_type& reference; 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef const value_type& const_reference; 1274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) typedef size_t size_type; 1284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) typedef ptrdiff_t difference_type; 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef random_access_iterator_tag _Iterator_category; 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS; 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) allocator_type get_allocator() const 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { return _STLP_CONVERT_ALLOCATOR((const allocator_type&)this->_M_end_of_storage, _Tp); } 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)private: 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _TrivialCopy; 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef typename __type_traits<_Tp>::has_trivial_copy_constructor _TrivialUCopy; 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined (_STLP_NO_MOVE_SEMANTIC) 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef typename __move_traits<_Tp>::implemented _Movable; 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef __false_type _Movable; 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 144cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // handles insertions on overflow 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void _M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __false_type& /*_Movable*/, 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) size_type __fill_len, bool __atend); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void _M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __true_type& /*_Movable*/, 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_type __fill_len, bool __atend) { 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) //We need to take care of self referencing here: 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (_M_is_inside(__x)) { 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) value_type __x_copy = __x; 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _M_insert_overflow_aux(__pos, __x_copy, __false_type(), __fill_len, __atend); 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _M_insert_overflow_aux(__pos, __x, __false_type(), __fill_len, __atend); 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void _M_insert_overflow(pointer __pos, const _Tp& __x, const __false_type& /*_TrivialCopy*/, 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_type __fill_len, bool __atend = false) 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { _M_insert_overflow_aux(__pos, __x, _Movable(), __fill_len, __atend); } 162cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) void _M_insert_overflow(pointer __pos, const _Tp& __x, const __true_type& /*_TrivialCopy*/, 163cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) size_type __fill_len, bool __atend = false); 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void _M_range_check(size_type __n) const { 165cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (__n >= size_type(this->_M_finish - this->_M_start)) 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) this->_M_throw_out_of_range(); 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) iterator begin() { return this->_M_start; } 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const_iterator begin() const { return this->_M_start; } 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) iterator end() { return this->_M_finish; } 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const_iterator end() const { return this->_M_finish; } 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reverse_iterator rbegin() { return reverse_iterator(end()); } 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reverse_iterator rend() { return reverse_iterator(begin()); } 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_type size() const { return size_type(this->_M_finish - this->_M_start); } 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_type max_size() const { 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_type __vector_max_size = size_type(-1) / sizeof(_Tp); 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename allocator_type::size_type __alloc_max_size = this->_M_end_of_storage.max_size(); 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return (__alloc_max_size < __vector_max_size)?__alloc_max_size:__vector_max_size; 185cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) size_type capacity() const { return size_type(this->_M_end_of_storage._M_data - this->_M_start); } 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool empty() const { return this->_M_start == this->_M_finish; } 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 190effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch reference operator[](size_type __n) { return *(begin() + __n); } 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const_reference operator[](size_type __n) const { return *(begin() + __n); } 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reference front() { return *begin(); } 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const_reference front() const { return *begin(); } 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reference back() { return *(end() - 1); } 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const_reference back() const { return *(end() - 1); } 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reference at(size_type __n) { _M_range_check(__n); return (*this)[__n]; } 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const_reference at(size_type __n) const { _M_range_check(__n); return (*this)[__n]; } 2004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#if !defined (_STLP_DONT_SUP_DFLT_PARAM) 2024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) explicit vector(const allocator_type& __a = allocator_type()) 2034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#else 204f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) vector() 205f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(allocator_type()) {} 206f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) vector(const allocator_type& __a) 207f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#endif 2084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__a) {} 2094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined (_STLP_DONT_SUP_DFLT_PARAM) 2111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)private: 212c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) //We always call _M_initialize with only 1 parameter. Default parameter 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) //is used to allow explicit instanciation of vector with types with no 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) //default constructor. 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void _M_initialize(size_type __n, const _Tp& __val = _STLP_DEFAULT_CONSTRUCTED(_Tp)) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { this->_M_finish = _STLP_PRIV __uninitialized_init(this->_M_start, __n, __val); } 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit vector(size_type __n) 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, allocator_type()) 2204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { _M_initialize(__n); } 2214ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch vector(size_type __n, const _Tp& __val, const allocator_type& __a = allocator_type()) 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit vector(size_type __n) 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, allocator_type()) 225c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) { this->_M_finish = _STLP_PRIV __uninitialized_init(this->_M_start, __n, _STLP_DEFAULT_CONSTRUCTED(_Tp)); } 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) vector(size_type __n, const _Tp& __val) 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, allocator_type()) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_start, __n, __val); } 2294ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch vector(size_type __n, const _Tp& __val, const allocator_type& __a) 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, __a) 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_start, __n, __val); } 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) vector(const _Self& __x) 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__x.size(), __x.get_allocator()) 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { this->_M_finish = _STLP_PRIV __ucopy_ptrs(__x.begin(), __x.end(), this->_M_start, _TrivialUCopy()); } 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) vector(__move_source<_Self> src) 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__move_source<_Base>(src.get())) 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {} 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined (_STLP_MEMBER_TEMPLATES) 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)private: 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template <class _Integer> 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void _M_initialize_aux(_Integer __n, _Integer __val, 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const __true_type& /*_IsIntegral*/) { 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_type __real_n; 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this->_M_start = this->_M_end_of_storage.allocate(__n, __real_n); 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this->_M_end_of_storage._M_data = this->_M_start + __real_n; 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_start, __n, __val); 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template <class _InputIterator> 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void _M_initialize_aux(_InputIterator __first, _InputIterator __last, 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const __false_type& /*_IsIntegral*/) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { _M_range_initialize(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator)); } 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check whether it's an integral type. If so, it's not an iterator. 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template <class _InputIterator> 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) vector(_InputIterator __first, _InputIterator __last, 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL ) 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__a) { 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _M_initialize_aux(__first, __last, _Integral()); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 268c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS) 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template <class _InputIterator> 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) vector(_InputIterator __first, _InputIterator __last) 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(allocator_type()) { 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _M_initialize_aux(__first, __last, _Integral()); 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# endif /* _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS */ 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else /* _STLP_MEMBER_TEMPLATES */ 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) vector(const _Tp* __first, const _Tp* __last, 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const allocator_type& __a = allocator_type()) 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__last - __first, __a) 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { this->_M_finish = _STLP_PRIV __ucopy_ptrs(__first, __last, this->_M_start, _TrivialUCopy()); } 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* _STLP_MEMBER_TEMPLATES */ 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) //As the vector container is a back insert oriented container it 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) //seems rather logical to destroy elements in reverse order. 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~vector() { _STLP_STD::_Destroy_Range(rbegin(), rend()); } 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _Self& operator=(const _Self& __x); 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void reserve(size_type __n); 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // assign(), a generalized assignment member function. Two 293c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // versions: one that takes a count, and one that takes a range. 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The range version is a member template, so we dispatch on whether 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // or not the type is an integer. 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void assign(size_type __n, const _Tp& __val) { _M_fill_assign(__n, __val); } 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void _M_fill_assign(size_type __n, const _Tp& __val); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 300c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined (_STLP_MEMBER_TEMPLATES) 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template <class _ForwardIter> 3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void _M_assign_aux(_ForwardIter __first, _ForwardIter __last, const forward_iterator_tag &) { 3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#else 3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void assign(const_iterator __first, const_iterator __last) { 3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) typedef const_iterator _ForwardIter; 3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif 3075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const size_type __len = distance(__first, __last); 3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (__len > capacity()) { 3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) size_type __n = __len; 3105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) iterator __tmp = _M_allocate_and_copy(__n, __first, __last); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _M_clear(); 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _M_set(__tmp, __tmp + __len, __tmp + __n); 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else if (size() >= __len) { 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) iterator __new_finish = copy(__first, __last, this->_M_start); 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) _STLP_STD::_Destroy_Range(__new_finish, this->_M_finish); 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this->_M_finish = __new_finish; 318 } 319 else { 320 _ForwardIter __mid = __first; 321 advance(__mid, size()); 322 copy(__first, __mid, this->_M_start); 323 this->_M_finish = uninitialized_copy(__mid, __last, this->_M_finish); 324 } 325 } 326 327#if defined (_STLP_MEMBER_TEMPLATES) 328 template <class _InputIter> 329 void _M_assign_aux(_InputIter __first, _InputIter __last, 330 const input_iterator_tag &) { 331 iterator __cur = begin(); 332 for ( ; __first != __last && __cur != end(); ++__cur, ++__first) 333 *__cur = *__first; 334 if (__first == __last) 335 erase(__cur, end()); 336 else 337 insert(end(), __first, __last); 338 } 339 340 template <class _Integer> 341 void _M_assign_dispatch(_Integer __n, _Integer __val, 342 const __true_type& /*_IsIntegral*/) 343 { _M_fill_assign(__n, __val); } 344 345 template <class _InputIter> 346 void _M_assign_dispatch(_InputIter __first, _InputIter __last, 347 const __false_type& /*_IsIntegral*/) 348 { _M_assign_aux(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); } 349 350 template <class _InputIterator> 351 void assign(_InputIterator __first, _InputIterator __last) { 352 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 353 _M_assign_dispatch(__first, __last, _Integral()); 354 } 355#endif /* _STLP_MEMBER_TEMPLATES */ 356 357#if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS) 358 void push_back(const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) { 359#else 360 void push_back(const _Tp& __x) { 361#endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/ 362 if (this->_M_finish != this->_M_end_of_storage._M_data) { 363 _Copy_Construct(this->_M_finish, __x); 364 ++this->_M_finish; 365 } 366 else 367 _M_insert_overflow(this->_M_finish, __x, _TrivialCopy(), 1UL, true); 368 } 369 370#if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS) 371 iterator insert(iterator __pos, const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)); 372#else 373 iterator insert(iterator __pos, const _Tp& __x); 374#endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/ 375 376#if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS) 377 void push_back() { push_back(_STLP_DEFAULT_CONSTRUCTED(_Tp)); } 378 iterator insert(iterator __pos) { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp)); } 379#endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/ 380 381 void swap(_Self& __x) { 382 _STLP_STD::swap(this->_M_start, __x._M_start); 383 _STLP_STD::swap(this->_M_finish, __x._M_finish); 384 this->_M_end_of_storage.swap(__x._M_end_of_storage); 385 } 386 387private: 388 void _M_fill_insert_aux (iterator __pos, size_type __n, const _Tp& __x, const __true_type& /*_Movable*/); 389 void _M_fill_insert_aux (iterator __pos, size_type __n, const _Tp& __x, const __false_type& /*_Movable*/); 390 void _M_fill_insert (iterator __pos, size_type __n, const _Tp& __x); 391 392 bool _M_is_inside(const value_type& __x) const { 393 return (&__x >= this->_M_start && &__x < this->_M_finish); 394 } 395 396#if defined (_STLP_MEMBER_TEMPLATES) 397 template <class _ForwardIterator> 398 void _M_range_insert_realloc(iterator __pos, 399 _ForwardIterator __first, _ForwardIterator __last, 400#else 401 void _M_range_insert_realloc(iterator __pos, 402 const_iterator __first, const_iterator __last, 403#endif /* _STLP_MEMBER_TEMPLATES */ 404 size_type __n) { 405 const size_type __old_size = size(); 406 size_type __len = __old_size + (max)(__old_size, __n); 407 pointer __new_start = this->_M_end_of_storage.allocate(__len, __len); 408 pointer __new_finish = __new_start; 409 _STLP_TRY { 410 __new_finish = _STLP_PRIV __uninitialized_move(this->_M_start, __pos, __new_start, _TrivialUCopy(), _Movable()); 411 __new_finish = uninitialized_copy(__first, __last, __new_finish); 412 __new_finish = _STLP_PRIV __uninitialized_move(__pos, this->_M_finish, __new_finish, _TrivialUCopy(), _Movable()); 413 } 414 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish), 415 this->_M_end_of_storage.deallocate(__new_start,__len))) 416 _M_clear_after_move(); 417 _M_set(__new_start, __new_finish, __new_start + __len); 418 } 419 420#if defined (_STLP_MEMBER_TEMPLATES) 421 template <class _ForwardIterator> 422 void _M_range_insert_aux(iterator __pos, 423 _ForwardIterator __first, _ForwardIterator __last, 424#else 425 void _M_range_insert_aux(iterator __pos, 426 const_iterator __first, const_iterator __last, 427#endif /* _STLP_MEMBER_TEMPLATES */ 428 size_type __n, const __true_type& /*_Movable*/) { 429 iterator __src = this->_M_finish - 1; 430 iterator __dst = __src + __n; 431 for (; __src >= __pos; --__dst, --__src) { 432 _STLP_STD::_Move_Construct(__dst, *__src); 433 _STLP_STD::_Destroy_Moved(__src); 434 } 435 uninitialized_copy(__first, __last, __pos); 436 this->_M_finish += __n; 437 } 438 439#if defined (_STLP_MEMBER_TEMPLATES) 440 template <class _ForwardIterator> 441 void _M_range_insert_aux(iterator __pos, 442 _ForwardIterator __first, _ForwardIterator __last, 443#else 444 void _M_range_insert_aux(iterator __pos, 445 const_iterator __first, const_iterator __last, 446#endif /* _STLP_MEMBER_TEMPLATES */ 447 size_type __n, const __false_type& /*_Movable*/) { 448 const size_type __elems_after = this->_M_finish - __pos; 449 pointer __old_finish = this->_M_finish; 450 if (__elems_after > __n) { 451 _STLP_PRIV __ucopy_ptrs(this->_M_finish - __n, this->_M_finish, this->_M_finish, _TrivialUCopy()); 452 this->_M_finish += __n; 453 _STLP_PRIV __copy_backward_ptrs(__pos, __old_finish - __n, __old_finish, _TrivialCopy()); 454 copy(__first, __last, __pos); 455 } 456 else { 457#if defined ( _STLP_MEMBER_TEMPLATES ) 458 _ForwardIterator __mid = __first; 459 advance(__mid, __elems_after); 460#else 461 const_pointer __mid = __first + __elems_after; 462#endif 463 uninitialized_copy(__mid, __last, this->_M_finish); 464 this->_M_finish += __n - __elems_after; 465 _STLP_PRIV __ucopy_ptrs(__pos, __old_finish, this->_M_finish, _TrivialUCopy()); 466 this->_M_finish += __elems_after; 467 copy(__first, __mid, __pos); 468 } /* elems_after */ 469 } 470 471 472#if defined (_STLP_MEMBER_TEMPLATES) 473 template <class _Integer> 474 void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val, 475 const __true_type&) 476 { _M_fill_insert(__pos, (size_type) __n, (_Tp) __val); } 477 478 template <class _InputIterator> 479 void _M_insert_dispatch(iterator __pos, 480 _InputIterator __first, _InputIterator __last, 481 const __false_type&) 482 { _M_range_insert(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator)); } 483 484public: 485 // Check whether it's an integral type. If so, it's not an iterator. 486 template <class _InputIterator> 487 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) { 488 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 489 _M_insert_dispatch(__pos, __first, __last, _Integral()); 490 } 491 492private: 493 template <class _InputIterator> 494 void _M_range_insert(iterator __pos, 495 _InputIterator __first, _InputIterator __last, 496 const input_iterator_tag &) { 497 for ( ; __first != __last; ++__first) { 498 __pos = insert(__pos, *__first); 499 ++__pos; 500 } 501 } 502 503 template <class _ForwardIterator> 504 void _M_range_insert(iterator __pos, 505 _ForwardIterator __first, _ForwardIterator __last, 506 const forward_iterator_tag &) { 507#else /* _STLP_MEMBER_TEMPLATES */ 508public: 509 void insert(iterator __pos, 510 const_iterator __first, const_iterator __last) { 511#endif /* _STLP_MEMBER_TEMPLATES */ 512 /* This method do not check self referencing. 513 * Standard forbids it, checked by the debug mode. 514 */ 515 if (__first != __last) { 516 size_type __n = distance(__first, __last); 517 518 if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n) { 519 _M_range_insert_aux(__pos, __first, __last, __n, _Movable()); 520 } 521 else { 522 _M_range_insert_realloc(__pos, __first, __last, __n); 523 } 524 } 525 } 526 527public: 528 void insert (iterator __pos, size_type __n, const _Tp& __x) 529 { _M_fill_insert(__pos, __n, __x); } 530 531 void pop_back() { 532 --this->_M_finish; 533 _STLP_STD::_Destroy(this->_M_finish); 534 } 535 536private: 537 iterator _M_erase(iterator __pos, const __true_type& /*_Movable*/) { 538 _STLP_STD::_Destroy(__pos); 539 iterator __dst = __pos, __src = __dst + 1; 540 iterator __end = end(); 541 for (; __src != __end; ++__dst, ++__src) { 542 _STLP_STD::_Move_Construct(__dst, *__src); 543 _STLP_STD::_Destroy_Moved(__src); 544 } 545 this->_M_finish = __dst; 546 return __pos; 547 } 548 iterator _M_erase(iterator __pos, const __false_type& /*_Movable*/) { 549 if (__pos + 1 != end()) 550 _STLP_PRIV __copy_ptrs(__pos + 1, this->_M_finish, __pos, _TrivialCopy()); 551 --this->_M_finish; 552 _STLP_STD::_Destroy(this->_M_finish); 553 return __pos; 554 } 555 iterator _M_erase(iterator __first, iterator __last, const __true_type& /*_Movable*/) { 556 iterator __dst = __first, __src = __last; 557 iterator __end = end(); 558 for (; __dst != __last && __src != __end; ++__dst, ++__src) { 559 _STLP_STD::_Destroy(__dst); 560 _STLP_STD::_Move_Construct(__dst, *__src); 561 } 562 if (__dst != __last) { 563 //There is more elements to erase than element to move: 564 _STLP_STD::_Destroy_Range(__dst, __last); 565 _STLP_STD::_Destroy_Moved_Range(__last, __end); 566 } 567 else { 568 //There is more element to move than element to erase: 569 for (; __src != __end; ++__dst, ++__src) { 570 _STLP_STD::_Destroy_Moved(__dst); 571 _STLP_STD::_Move_Construct(__dst, *__src); 572 } 573 _STLP_STD::_Destroy_Moved_Range(__dst, __end); 574 } 575 this->_M_finish = __dst; 576 return __first; 577 } 578 iterator _M_erase(iterator __first, iterator __last, const __false_type& /*_Movable*/) { 579 pointer __i = _STLP_PRIV __copy_ptrs(__last, this->_M_finish, __first, _TrivialCopy()); 580 _STLP_STD::_Destroy_Range(__i, this->_M_finish); 581 this->_M_finish = __i; 582 return __first; 583 } 584 585public: 586 iterator erase(iterator __pos) { 587 return _M_erase(__pos, _Movable()); 588 } 589 iterator erase(iterator __first, iterator __last) { 590 if (__first == __last) 591 return __first; 592 return _M_erase(__first, __last, _Movable()); 593 } 594 595#if !defined (_STLP_DONT_SUP_DFLT_PARAM) 596 void resize(size_type __new_size, const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) { 597#else 598 void resize(size_type __new_size, const _Tp& __x) { 599#endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 600 if (__new_size < size()) 601 erase(begin() + __new_size, end()); 602 else 603 insert(end(), __new_size - size(), __x); 604 } 605 606#if defined (_STLP_DONT_SUP_DFLT_PARAM) 607 void resize(size_type __new_size) { resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); } 608#endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 609 610 void clear() { 611 erase(begin(), end()); 612 } 613 614private: 615 void _M_clear() { 616 _STLP_STD::_Destroy_Range(rbegin(), rend()); 617 this->_M_end_of_storage.deallocate(this->_M_start, this->_M_end_of_storage._M_data - this->_M_start); 618 } 619 620 void _M_clear_after_move() { 621 _STLP_STD::_Destroy_Moved_Range(rbegin(), rend()); 622 this->_M_end_of_storage.deallocate(this->_M_start, this->_M_end_of_storage._M_data - this->_M_start); 623 } 624 625 void _M_set(pointer __s, pointer __f, pointer __e) { 626 this->_M_start = __s; 627 this->_M_finish = __f; 628 this->_M_end_of_storage._M_data = __e; 629 } 630 631#if defined (_STLP_MEMBER_TEMPLATES) 632 template <class _ForwardIterator> 633 pointer _M_allocate_and_copy(size_type& __n, 634 _ForwardIterator __first, _ForwardIterator __last) 635#else /* _STLP_MEMBER_TEMPLATES */ 636 pointer _M_allocate_and_copy(size_type& __n, 637 const_pointer __first, const_pointer __last) 638#endif /* _STLP_MEMBER_TEMPLATES */ 639 { 640 pointer __result = this->_M_end_of_storage.allocate(__n, __n); 641 _STLP_TRY { 642 uninitialized_copy(__first, __last, __result); 643 return __result; 644 } 645 _STLP_UNWIND(this->_M_end_of_storage.deallocate(__result, __n)) 646 _STLP_RET_AFTER_THROW(__result) 647 } 648 649 650#if defined (_STLP_MEMBER_TEMPLATES) 651 template <class _InputIterator> 652 void _M_range_initialize(_InputIterator __first, _InputIterator __last, 653 const input_iterator_tag &) { 654 for ( ; __first != __last; ++__first) 655 push_back(*__first); 656 } 657 // This function is only called by the constructor. 658 template <class _ForwardIterator> 659 void _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last, 660 const forward_iterator_tag &) { 661 size_type __n = distance(__first, __last); 662 this->_M_start = this->_M_end_of_storage.allocate(__n, __n); 663 this->_M_end_of_storage._M_data = this->_M_start + __n; 664 this->_M_finish = uninitialized_copy(__first, __last, this->_M_start); 665 } 666#endif /* _STLP_MEMBER_TEMPLATES */ 667}; 668 669#if defined (vector) 670# undef vector 671_STLP_MOVE_TO_STD_NAMESPACE 672#endif 673 674_STLP_END_NAMESPACE 675 676#if !defined (_STLP_LINK_TIME_INSTANTIATION) 677# include <stl/_vector.c> 678#endif 679 680#if defined (_STLP_USE_PTR_SPECIALIZATIONS) 681# include <stl/pointers/_vector.h> 682#endif 683 684//We define the bool specialization before the debug interfave 685//to benefit of the debug version of vector even for the bool 686//specialization. 687#if !defined (_STLP_NO_BOOL) || !defined (_STLP_NO_EXTENSIONS) 688# if !defined (_STLP_INTERNAL_BVECTOR_H) 689# include <stl/_bvector.h> 690# endif 691#endif 692 693#if defined (_STLP_DEBUG) 694# include <stl/debug/_vector.h> 695#endif 696 697_STLP_BEGIN_NAMESPACE 698 699#if !defined (_STLP_NO_BOOL) && !defined (_STLP_NO_EXTENSIONS) 700// This typedef is non-standard. It is provided for backward compatibility. 701typedef vector<bool, allocator<bool> > bit_vector; 702#endif 703 704#define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc> 705#define _STLP_TEMPLATE_CONTAINER vector<_Tp, _Alloc> 706#include <stl/_relops_cont.h> 707#undef _STLP_TEMPLATE_CONTAINER 708#undef _STLP_TEMPLATE_HEADER 709 710#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) 711template <class _Tp, class _Alloc> 712struct __move_traits<vector<_Tp, _Alloc> > { 713 typedef __stlp_movable implemented; 714 typedef typename __move_traits<_Alloc>::complete complete; 715#if defined (__BORLANDC__) && (__BORLANDC__ < 0x560) 716 // disable incorrect "dependent type qualifier" error 717 typedef __false_type _Ret; 718#endif 719}; 720 721# if !defined (_STLP_DEBUG) 722template <class _Tp, class _Alloc> 723struct _DefaultZeroValue<vector<_Tp, _Alloc> > 724{ typedef typename __type_traits<_Alloc>::has_trivial_default_constructor _Ret; }; 725# endif 726 727#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */ 728 729_STLP_END_NAMESPACE 730 731#endif /* _STLP_VECTOR_H */ 732 733// Local Variables: 734// mode:C++ 735// End: 736