Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygen_vector.h
Go to the documentation of this file.
00001 /* 00002 * 00003 * Copyright (c) 1994 00004 * Hewlett-Packard Company 00005 * 00006 * Copyright (c) 1996,1997 00007 * Silicon Graphics Computer Systems, Inc. 00008 * 00009 * Copyright (c) 1997 00010 * Moscow Center for SPARC Technology 00011 * 00012 * Copyright (c) 1999 00013 * Boris Fomitchev 00014 * 00015 * This material is provided "as is", with absolutely no warranty expressed 00016 * or implied. Any use is at your own risk. 00017 * 00018 * Permission to use or copy this software for any purpose is hereby granted 00019 * without fee, provided the above notices are retained on all copies. 00020 * Permission to modify the code and to distribute modified code is granted, 00021 * provided the above notices are retained, and a notice that the code was 00022 * modified is included with the above copyright notice. 00023 * 00024 */ 00025 00026 /* NOTE: This is an internal header file, included by other STL headers. 00027 * You should not attempt to use it directly. 00028 */ 00029 00030 #ifndef _STLP_INTERNAL_VECTOR_H 00031 #define _STLP_INTERNAL_VECTOR_H 00032 00033 #ifndef _STLP_INTERNAL_ALGOBASE_H 00034 # include <stl/_algobase.h> 00035 #endif 00036 00037 #ifndef _STLP_INTERNAL_ALLOC_H 00038 # include <stl/_alloc.h> 00039 #endif 00040 00041 #ifndef _STLP_INTERNAL_ITERATOR_H 00042 # include <stl/_iterator.h> 00043 #endif 00044 00045 #ifndef _STLP_INTERNAL_UNINITIALIZED_H 00046 # include <stl/_uninitialized.h> 00047 #endif 00048 00049 _STLP_BEGIN_NAMESPACE 00050 00051 // The vector base class serves one purpose, its constructor and 00052 // destructor allocate (but don't initialize) storage. This makes 00053 // exception safety easier. 00054 00055 _STLP_MOVE_TO_PRIV_NAMESPACE 00056 00057 template <class _Tp, class _Alloc> 00058 class _Vector_base { 00059 public: 00060 typedef _Vector_base<_Tp, _Alloc> _Self; 00061 _STLP_FORCE_ALLOCATORS(_Tp, _Alloc) 00062 typedef _Alloc allocator_type; 00063 typedef _Tp* pointer; 00064 typedef _STLP_alloc_proxy<pointer, _Tp, allocator_type> _AllocProxy; 00065 00066 _Vector_base(const _Alloc& __a) 00067 : _M_start(0), _M_finish(0), _M_end_of_storage(__a, 0) {} 00068 00069 _Vector_base(size_t __n, const _Alloc& __a) 00070 : _M_start(0), _M_finish(0), _M_end_of_storage(__a, 0) { 00071 _M_start = _M_end_of_storage.allocate(__n, __n); 00072 _M_finish = _M_start; 00073 _M_end_of_storage._M_data = _M_start + __n; 00074 _STLP_MPWFIX_TRY _STLP_MPWFIX_CATCH 00075 } 00076 00077 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00078 _Vector_base(__move_source<_Self> src) 00079 : _M_start(src.get()._M_start), _M_finish(src.get()._M_finish), 00080 _M_end_of_storage(__move_source<_AllocProxy>(src.get()._M_end_of_storage)) { 00081 //Set the source as empty: 00082 src.get()._M_finish = src.get()._M_end_of_storage._M_data = src.get()._M_start = 0; 00083 } 00084 #endif 00085 00086 ~_Vector_base() { 00087 if (_M_start != _STLP_DEFAULT_CONSTRUCTED(pointer)) 00088 _M_end_of_storage.deallocate(_M_start, _M_end_of_storage._M_data - _M_start); 00089 } 00090 00091 protected: 00092 void _STLP_FUNCTION_THROWS _M_throw_length_error() const; 00093 void _STLP_FUNCTION_THROWS _M_throw_out_of_range() const; 00094 00095 pointer _M_start; 00096 pointer _M_finish; 00097 _AllocProxy _M_end_of_storage; 00098 }; 00099 00100 #if defined (_STLP_USE_PTR_SPECIALIZATIONS) 00101 # define vector _STLP_PTR_IMPL_NAME(vector) 00102 #elif defined (_STLP_DEBUG) 00103 # define vector _STLP_NON_DBG_NAME(vector) 00104 #else 00105 _STLP_MOVE_TO_STD_NAMESPACE 00106 #endif 00107 00108 template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) > 00109 class vector : protected _STLP_PRIV _Vector_base<_Tp, _Alloc> 00110 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (vector) 00111 , public __stlport_class<vector<_Tp, _Alloc> > 00112 #endif 00113 { 00114 private: 00115 typedef _STLP_PRIV _Vector_base<_Tp, _Alloc> _Base; 00116 typedef vector<_Tp, _Alloc> _Self; 00117 public: 00118 _STLP_FORCE_ALLOCATORS(_Tp, _Alloc) 00119 typedef typename _Base::allocator_type allocator_type; 00120 00121 typedef _Tp value_type; 00122 typedef value_type* pointer; 00123 typedef const value_type* const_pointer; 00124 typedef value_type* iterator; 00125 typedef const value_type* const_iterator; 00126 00127 typedef value_type& reference; 00128 typedef const value_type& const_reference; 00129 typedef size_t size_type; 00130 typedef ptrdiff_t difference_type; 00131 typedef random_access_iterator_tag _Iterator_category; 00132 00133 _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS; 00134 00135 allocator_type get_allocator() const 00136 { return _STLP_CONVERT_ALLOCATOR((const allocator_type&)this->_M_end_of_storage, _Tp); } 00137 00138 private: 00139 #if defined (_STLP_NO_MOVE_SEMANTIC) 00140 typedef __false_type _Movable; 00141 #endif 00142 00143 // handles insertions on overflow 00144 void _M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __false_type& /*_Movable*/, 00145 size_type __fill_len, bool __atend); 00146 void _M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __true_type& /*_Movable*/, 00147 size_type __fill_len, bool __atend) { 00148 //We need to take care of self referencing here: 00149 if (_M_is_inside(__x)) { 00150 value_type __x_copy = __x; 00151 _M_insert_overflow_aux(__pos, __x_copy, __false_type(), __fill_len, __atend); 00152 return; 00153 } 00154 _M_insert_overflow_aux(__pos, __x, __false_type(), __fill_len, __atend); 00155 } 00156 00157 void _M_insert_overflow(pointer __pos, const _Tp& __x, const __false_type& /*_TrivialCopy*/, 00158 size_type __fill_len, bool __atend = false) { 00159 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00160 typedef typename __move_traits<_Tp>::implemented _Movable; 00161 #endif 00162 _M_insert_overflow_aux(__pos, __x, _Movable(), __fill_len, __atend); 00163 } 00164 void _M_insert_overflow(pointer __pos, const _Tp& __x, const __true_type& /*_TrivialCopy*/, 00165 size_type __fill_len, bool __atend = false); 00166 void _M_range_check(size_type __n) const { 00167 if (__n >= size_type(this->_M_finish - this->_M_start)) 00168 this->_M_throw_out_of_range(); 00169 } 00170 00171 size_type _M_compute_next_size(size_type __n) { 00172 const size_type __size = size(); 00173 if (__n > max_size() - __size) 00174 this->_M_throw_length_error(); 00175 size_type __len = __size + (max)(__n, __size); 00176 if (__len > max_size() || __len < __size) 00177 __len = max_size(); // overflow 00178 return __len; 00179 } 00180 00181 public: 00182 iterator begin() { return this->_M_start; } 00183 const_iterator begin() const { return this->_M_start; } 00184 iterator end() { return this->_M_finish; } 00185 const_iterator end() const { return this->_M_finish; } 00186 00187 reverse_iterator rbegin() { return reverse_iterator(end()); } 00188 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } 00189 reverse_iterator rend() { return reverse_iterator(begin()); } 00190 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } 00191 00192 size_type size() const { return size_type(this->_M_finish - this->_M_start); } 00193 size_type max_size() const { 00194 size_type __vector_max_size = size_type(-1) / sizeof(_Tp); 00195 typename allocator_type::size_type __alloc_max_size = this->_M_end_of_storage.max_size(); 00196 return (__alloc_max_size < __vector_max_size)?__alloc_max_size:__vector_max_size; 00197 } 00198 00199 size_type capacity() const { return size_type(this->_M_end_of_storage._M_data - this->_M_start); } 00200 bool empty() const { return this->_M_start == this->_M_finish; } 00201 00202 reference operator[](size_type __n) { return *(begin() + __n); } 00203 const_reference operator[](size_type __n) const { return *(begin() + __n); } 00204 00205 reference front() { return *begin(); } 00206 const_reference front() const { return *begin(); } 00207 reference back() { return *(end() - 1); } 00208 const_reference back() const { return *(end() - 1); } 00209 00210 reference at(size_type __n) { _M_range_check(__n); return (*this)[__n]; } 00211 const_reference at(size_type __n) const { _M_range_check(__n); return (*this)[__n]; } 00212 00213 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) 00214 explicit vector(const allocator_type& __a = allocator_type()) 00215 #else 00216 vector() 00217 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(allocator_type()) {} 00218 vector(const allocator_type& __a) 00219 #endif 00220 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__a) {} 00221 00222 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) 00223 private: 00224 //We always call _M_initialize with only 1 parameter. Default parameter 00225 //is used to allow explicit instanciation of vector with types with no 00226 //default constructor. 00227 void _M_initialize(size_type __n, const _Tp& __val = _STLP_DEFAULT_CONSTRUCTED(_Tp)) 00228 { this->_M_finish = _STLP_PRIV __uninitialized_init(this->_M_start, __n, __val); } 00229 public: 00230 explicit vector(size_type __n) 00231 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, allocator_type()) 00232 { _M_initialize(__n); } 00233 vector(size_type __n, const _Tp& __val, const allocator_type& __a = allocator_type()) 00234 #else 00235 explicit vector(size_type __n) 00236 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, allocator_type()) 00237 { this->_M_finish = _STLP_PRIV __uninitialized_init(this->_M_start, __n, _STLP_DEFAULT_CONSTRUCTED(_Tp)); } 00238 vector(size_type __n, const _Tp& __val) 00239 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, allocator_type()) 00240 { this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_start, __n, __val); } 00241 vector(size_type __n, const _Tp& __val, const allocator_type& __a) 00242 #endif 00243 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, __a) 00244 { this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_start, __n, __val); } 00245 00246 vector(const _Self& __x) 00247 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__x.size(), __x.get_allocator()) { 00248 typedef typename __type_traits<_Tp>::has_trivial_copy_constructor _TrivialUCopy; 00249 this->_M_finish = _STLP_PRIV __ucopy_ptrs(__x.begin(), __x.end(), this->_M_start, _TrivialUCopy()); 00250 } 00251 00252 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00253 vector(__move_source<_Self> src) 00254 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__move_source<_Base>(src.get())) 00255 {} 00256 #endif 00257 00258 #if defined (_STLP_MEMBER_TEMPLATES) 00259 private: 00260 template <class _Integer> 00261 void _M_initialize_aux(_Integer __n, _Integer __val, 00262 const __true_type& /*_IsIntegral*/) { 00263 size_type __real_n = __n; 00264 this->_M_start = this->_M_end_of_storage.allocate(__n, __real_n); 00265 this->_M_end_of_storage._M_data = this->_M_start + __real_n; 00266 this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_start, __n, __val); 00267 } 00268 00269 template <class _InputIterator> 00270 void _M_initialize_aux(_InputIterator __first, _InputIterator __last, 00271 const __false_type& /*_IsIntegral*/) 00272 { _M_range_initialize(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator)); } 00273 00274 public: 00275 // Check whether it's an integral type. If so, it's not an iterator. 00276 template <class _InputIterator> 00277 vector(_InputIterator __first, _InputIterator __last, 00278 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL ) 00279 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__a) { 00280 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00281 _M_initialize_aux(__first, __last, _Integral()); 00282 } 00283 00284 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS) 00285 template <class _InputIterator> 00286 vector(_InputIterator __first, _InputIterator __last) 00287 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(allocator_type()) { 00288 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00289 _M_initialize_aux(__first, __last, _Integral()); 00290 } 00291 # endif /* _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS */ 00292 00293 #else /* _STLP_MEMBER_TEMPLATES */ 00294 vector(const _Tp* __first, const _Tp* __last, 00295 const allocator_type& __a = allocator_type()) 00296 : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__last - __first, __a) { 00297 typedef typename __type_traits<_Tp>::has_trivial_copy_constructor _TrivialUCopy; 00298 this->_M_finish = _STLP_PRIV __ucopy_ptrs(__first, __last, this->_M_start, _TrivialUCopy()); 00299 } 00300 #endif /* _STLP_MEMBER_TEMPLATES */ 00301 00302 //As the vector container is a back insert oriented container it 00303 //seems rather logical to destroy elements in reverse order. 00304 ~vector() { _STLP_STD::_Destroy_Range(rbegin(), rend()); } 00305 00306 _Self& operator=(const _Self& __x); 00307 00308 void reserve(size_type __n); 00309 00310 // assign(), a generalized assignment member function. Two 00311 // versions: one that takes a count, and one that takes a range. 00312 // The range version is a member template, so we dispatch on whether 00313 // or not the type is an integer. 00314 00315 void assign(size_type __n, const _Tp& __val) { _M_fill_assign(__n, __val); } 00316 void _M_fill_assign(size_type __n, const _Tp& __val); 00317 00318 #if defined (_STLP_MEMBER_TEMPLATES) 00319 template <class _ForwardIter> 00320 void _M_assign_aux(_ForwardIter __first, _ForwardIter __last, const forward_iterator_tag &) { 00321 #else 00322 void assign(const_iterator __first, const_iterator __last) { 00323 typedef const_iterator _ForwardIter; 00324 #endif 00325 const size_type __len = _STLP_STD::distance(__first, __last); 00326 if (__len > capacity()) { 00327 size_type __n = __len; 00328 iterator __tmp = _M_allocate_and_copy(__n, __first, __last); 00329 _M_clear(); 00330 _M_set(__tmp, __tmp + __len, __tmp + __n); 00331 } 00332 else if (size() >= __len) { 00333 iterator __new_finish = copy(__first, __last, this->_M_start); 00334 _STLP_STD::_Destroy_Range(__new_finish, this->_M_finish); 00335 this->_M_finish = __new_finish; 00336 } 00337 else { 00338 _ForwardIter __mid = __first; 00339 _STLP_STD::advance(__mid, size()); 00340 _STLP_STD::copy(__first, __mid, this->_M_start); 00341 this->_M_finish = _STLP_STD::uninitialized_copy(__mid, __last, this->_M_finish); 00342 } 00343 } 00344 00345 #if defined (_STLP_MEMBER_TEMPLATES) 00346 template <class _InputIter> 00347 void _M_assign_aux(_InputIter __first, _InputIter __last, 00348 const input_iterator_tag &) { 00349 iterator __cur = begin(); 00350 for ( ; __first != __last && __cur != end(); ++__cur, ++__first) 00351 *__cur = *__first; 00352 if (__first == __last) 00353 erase(__cur, end()); 00354 else 00355 insert(end(), __first, __last); 00356 } 00357 00358 template <class _Integer> 00359 void _M_assign_dispatch(_Integer __n, _Integer __val, 00360 const __true_type& /*_IsIntegral*/) 00361 { _M_fill_assign(__n, __val); } 00362 00363 template <class _InputIter> 00364 void _M_assign_dispatch(_InputIter __first, _InputIter __last, 00365 const __false_type& /*_IsIntegral*/) 00366 { _M_assign_aux(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); } 00367 00368 template <class _InputIterator> 00369 void assign(_InputIterator __first, _InputIterator __last) { 00370 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00371 _M_assign_dispatch(__first, __last, _Integral()); 00372 } 00373 #endif 00374 00375 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS) 00376 void push_back(const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) { 00377 #else 00378 void push_back(const _Tp& __x) { 00379 #endif 00380 if (this->_M_finish != this->_M_end_of_storage._M_data) { 00381 _Copy_Construct(this->_M_finish, __x); 00382 ++this->_M_finish; 00383 } 00384 else { 00385 typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _TrivialCopy; 00386 _M_insert_overflow(this->_M_finish, __x, _TrivialCopy(), 1, true); 00387 } 00388 } 00389 00390 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS) 00391 iterator insert(iterator __pos, const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)); 00392 #else 00393 iterator insert(iterator __pos, const _Tp& __x); 00394 #endif 00395 00396 #if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS) 00397 void push_back() { push_back(_STLP_DEFAULT_CONSTRUCTED(_Tp)); } 00398 iterator insert(iterator __pos) { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp)); } 00399 #endif 00400 00401 void swap(_Self& __x) { 00402 _STLP_STD::swap(this->_M_start, __x._M_start); 00403 _STLP_STD::swap(this->_M_finish, __x._M_finish); 00404 this->_M_end_of_storage.swap(__x._M_end_of_storage); 00405 } 00406 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) 00407 void _M_swap_workaround(_Self& __x) { swap(__x); } 00408 #endif 00409 00410 private: 00411 void _M_fill_insert_aux (iterator __pos, size_type __n, const _Tp& __x, const __true_type& /*_Movable*/); 00412 void _M_fill_insert_aux (iterator __pos, size_type __n, const _Tp& __x, const __false_type& /*_Movable*/); 00413 void _M_fill_insert (iterator __pos, size_type __n, const _Tp& __x); 00414 00415 bool _M_is_inside(const value_type& __x) const { 00416 return (&__x >= this->_M_start && &__x < this->_M_finish); 00417 } 00418 00419 #if defined (_STLP_MEMBER_TEMPLATES) 00420 template <class _ForwardIterator> 00421 void _M_range_insert_realloc(iterator __pos, 00422 _ForwardIterator __first, _ForwardIterator __last, 00423 #else 00424 void _M_range_insert_realloc(iterator __pos, 00425 const_iterator __first, const_iterator __last, 00426 #endif 00427 size_type __n) { 00428 typedef typename __type_traits<_Tp>::has_trivial_copy_constructor _TrivialUCopy; 00429 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00430 typedef typename __move_traits<_Tp>::implemented _Movable; 00431 #endif 00432 size_type __len = _M_compute_next_size(__n); 00433 pointer __new_start = this->_M_end_of_storage.allocate(__len, __len); 00434 pointer __new_finish = __new_start; 00435 _STLP_TRY { 00436 __new_finish = _STLP_PRIV __uninitialized_move(this->_M_start, __pos, __new_start, _TrivialUCopy(), _Movable()); 00437 __new_finish = uninitialized_copy(__first, __last, __new_finish); 00438 __new_finish = _STLP_PRIV __uninitialized_move(__pos, this->_M_finish, __new_finish, _TrivialUCopy(), _Movable()); 00439 } 00440 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish), 00441 this->_M_end_of_storage.deallocate(__new_start,__len))) 00442 _M_clear_after_move(); 00443 _M_set(__new_start, __new_finish, __new_start + __len); 00444 } 00445 00446 #if defined (_STLP_MEMBER_TEMPLATES) 00447 template <class _ForwardIterator> 00448 void _M_range_insert_aux(iterator __pos, 00449 _ForwardIterator __first, _ForwardIterator __last, 00450 #else 00451 void _M_range_insert_aux(iterator __pos, 00452 const_iterator __first, const_iterator __last, 00453 #endif 00454 size_type __n, const __true_type& /*_Movable*/) { 00455 iterator __src = this->_M_finish - 1; 00456 iterator __dst = __src + __n; 00457 for (; __src >= __pos; --__dst, --__src) { 00458 _STLP_STD::_Move_Construct(__dst, *__src); 00459 _STLP_STD::_Destroy_Moved(__src); 00460 } 00461 uninitialized_copy(__first, __last, __pos); 00462 this->_M_finish += __n; 00463 } 00464 00465 #if defined (_STLP_MEMBER_TEMPLATES) 00466 template <class _ForwardIterator> 00467 void _M_range_insert_aux(iterator __pos, 00468 _ForwardIterator __first, _ForwardIterator __last, 00469 #else 00470 void _M_range_insert_aux(iterator __pos, 00471 const_iterator __first, const_iterator __last, 00472 #endif 00473 size_type __n, const __false_type& /*_Movable*/) { 00474 typedef typename __type_traits<_Tp>::has_trivial_copy_constructor _TrivialUCopy; 00475 typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _TrivialCopy; 00476 const size_type __elems_after = this->_M_finish - __pos; 00477 pointer __old_finish = this->_M_finish; 00478 if (__elems_after > __n) { 00479 _STLP_PRIV __ucopy_ptrs(this->_M_finish - __n, this->_M_finish, this->_M_finish, _TrivialUCopy()); 00480 this->_M_finish += __n; 00481 _STLP_PRIV __copy_backward_ptrs(__pos, __old_finish - __n, __old_finish, _TrivialCopy()); 00482 copy(__first, __last, __pos); 00483 } 00484 else { 00485 #if defined ( _STLP_MEMBER_TEMPLATES ) 00486 _ForwardIterator __mid = __first; 00487 _STLP_STD::advance(__mid, __elems_after); 00488 #else 00489 const_pointer __mid = __first + __elems_after; 00490 #endif 00491 uninitialized_copy(__mid, __last, this->_M_finish); 00492 this->_M_finish += __n - __elems_after; 00493 _STLP_PRIV __ucopy_ptrs(__pos, __old_finish, this->_M_finish, _TrivialUCopy()); 00494 this->_M_finish += __elems_after; 00495 copy(__first, __mid, __pos); 00496 } /* elems_after */ 00497 } 00498 00499 00500 #if defined (_STLP_MEMBER_TEMPLATES) 00501 template <class _Integer> 00502 void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val, 00503 const __true_type&) 00504 { _M_fill_insert(__pos, (size_type) __n, (_Tp) __val); } 00505 00506 template <class _InputIterator> 00507 void _M_insert_dispatch(iterator __pos, 00508 _InputIterator __first, _InputIterator __last, 00509 const __false_type&) 00510 { _M_range_insert(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator)); } 00511 00512 public: 00513 // Check whether it's an integral type. If so, it's not an iterator. 00514 template <class _InputIterator> 00515 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) { 00516 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00517 _M_insert_dispatch(__pos, __first, __last, _Integral()); 00518 } 00519 00520 private: 00521 template <class _InputIterator> 00522 void _M_range_insert(iterator __pos, 00523 _InputIterator __first, _InputIterator __last, 00524 const input_iterator_tag &) { 00525 for ( ; __first != __last; ++__first) { 00526 __pos = insert(__pos, *__first); 00527 ++__pos; 00528 } 00529 } 00530 00531 template <class _ForwardIterator> 00532 void _M_range_insert(iterator __pos, 00533 _ForwardIterator __first, _ForwardIterator __last, 00534 const forward_iterator_tag &) { 00535 #else 00536 public: 00537 void insert(iterator __pos, 00538 const_iterator __first, const_iterator __last) { 00539 #endif 00540 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00541 typedef typename __move_traits<_Tp>::implemented _Movable; 00542 #endif 00543 /* This method do not check self referencing. 00544 * Standard forbids it, checked by the debug mode. 00545 */ 00546 if (__first != __last) { 00547 size_type __n = _STLP_STD::distance(__first, __last); 00548 00549 if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n) { 00550 _M_range_insert_aux(__pos, __first, __last, __n, _Movable()); 00551 } 00552 else { 00553 _M_range_insert_realloc(__pos, __first, __last, __n); 00554 } 00555 } 00556 } 00557 00558 public: 00559 void insert (iterator __pos, size_type __n, const _Tp& __x) 00560 { _M_fill_insert(__pos, __n, __x); } 00561 00562 void pop_back() { 00563 --this->_M_finish; 00564 _STLP_STD::_Destroy(this->_M_finish); 00565 } 00566 00567 private: 00568 iterator _M_erase(iterator __pos, const __true_type& /*_Movable*/) { 00569 _STLP_STD::_Destroy(__pos); 00570 iterator __dst = __pos, __src = __dst + 1; 00571 iterator __end = end(); 00572 for (; __src != __end; ++__dst, ++__src) { 00573 _STLP_STD::_Move_Construct(__dst, *__src); 00574 _STLP_STD::_Destroy_Moved(__src); 00575 } 00576 this->_M_finish = __dst; 00577 return __pos; 00578 } 00579 iterator _M_erase(iterator __pos, const __false_type& /*_Movable*/) { 00580 if (__pos + 1 != end()) { 00581 typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _TrivialCopy; 00582 _STLP_PRIV __copy_ptrs(__pos + 1, this->_M_finish, __pos, _TrivialCopy()); 00583 } 00584 --this->_M_finish; 00585 _STLP_STD::_Destroy(this->_M_finish); 00586 return __pos; 00587 } 00588 iterator _M_erase(iterator __first, iterator __last, const __true_type& /*_Movable*/) { 00589 iterator __dst = __first, __src = __last; 00590 iterator __end = end(); 00591 for (; __dst != __last && __src != __end; ++__dst, ++__src) { 00592 _STLP_STD::_Destroy(__dst); 00593 _STLP_STD::_Move_Construct(__dst, *__src); 00594 } 00595 if (__dst != __last) { 00596 //There is more elements to erase than element to move: 00597 _STLP_STD::_Destroy_Range(__dst, __last); 00598 _STLP_STD::_Destroy_Moved_Range(__last, __end); 00599 } 00600 else { 00601 //There is more element to move than element to erase: 00602 for (; __src != __end; ++__dst, ++__src) { 00603 _STLP_STD::_Destroy_Moved(__dst); 00604 _STLP_STD::_Move_Construct(__dst, *__src); 00605 } 00606 _STLP_STD::_Destroy_Moved_Range(__dst, __end); 00607 } 00608 this->_M_finish = __dst; 00609 return __first; 00610 } 00611 iterator _M_erase(iterator __first, iterator __last, const __false_type& /*_Movable*/) { 00612 typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _TrivialCopy; 00613 pointer __i = _STLP_PRIV __copy_ptrs(__last, this->_M_finish, __first, _TrivialCopy()); 00614 _STLP_STD::_Destroy_Range(__i, this->_M_finish); 00615 this->_M_finish = __i; 00616 return __first; 00617 } 00618 00619 public: 00620 iterator erase(iterator __pos) { 00621 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00622 typedef typename __move_traits<_Tp>::implemented _Movable; 00623 #endif 00624 return _M_erase(__pos, _Movable()); 00625 } 00626 iterator erase(iterator __first, iterator __last) { 00627 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00628 typedef typename __move_traits<_Tp>::implemented _Movable; 00629 #endif 00630 if (__first == __last) 00631 return __first; 00632 return _M_erase(__first, __last, _Movable()); 00633 } 00634 00635 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) 00636 void resize(size_type __new_size, const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) { 00637 #else 00638 void resize(size_type __new_size, const _Tp& __x) { 00639 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00640 if (__new_size < size()) 00641 erase(begin() + __new_size, end()); 00642 else 00643 insert(end(), __new_size - size(), __x); 00644 } 00645 00646 #if defined (_STLP_DONT_SUP_DFLT_PARAM) 00647 void resize(size_type __new_size) { resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); } 00648 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00649 00650 void clear() { 00651 erase(begin(), end()); 00652 } 00653 00654 private: 00655 void _M_clear() { 00656 _STLP_STD::_Destroy_Range(rbegin(), rend()); 00657 this->_M_end_of_storage.deallocate(this->_M_start, this->_M_end_of_storage._M_data - this->_M_start); 00658 } 00659 00660 void _M_clear_after_move() { 00661 _STLP_STD::_Destroy_Moved_Range(rbegin(), rend()); 00662 this->_M_end_of_storage.deallocate(this->_M_start, this->_M_end_of_storage._M_data - this->_M_start); 00663 } 00664 00665 void _M_set(pointer __s, pointer __f, pointer __e) { 00666 this->_M_start = __s; 00667 this->_M_finish = __f; 00668 this->_M_end_of_storage._M_data = __e; 00669 } 00670 00671 #if defined (_STLP_MEMBER_TEMPLATES) 00672 template <class _ForwardIterator> 00673 pointer _M_allocate_and_copy(size_type& __n, 00674 _ForwardIterator __first, _ForwardIterator __last) 00675 #else /* _STLP_MEMBER_TEMPLATES */ 00676 pointer _M_allocate_and_copy(size_type& __n, 00677 const_pointer __first, const_pointer __last) 00678 #endif /* _STLP_MEMBER_TEMPLATES */ 00679 { 00680 pointer __result = this->_M_end_of_storage.allocate(__n, __n); 00681 _STLP_TRY { 00682 uninitialized_copy(__first, __last, __result); 00683 return __result; 00684 } 00685 _STLP_UNWIND(this->_M_end_of_storage.deallocate(__result, __n)) 00686 _STLP_RET_AFTER_THROW(__result) 00687 } 00688 00689 00690 #if defined (_STLP_MEMBER_TEMPLATES) 00691 template <class _InputIterator> 00692 void _M_range_initialize(_InputIterator __first, _InputIterator __last, 00693 const input_iterator_tag &) { 00694 for ( ; __first != __last; ++__first) 00695 push_back(*__first); 00696 } 00697 // This function is only called by the constructor. 00698 template <class _ForwardIterator> 00699 void _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last, 00700 const forward_iterator_tag &) { 00701 size_type __n = _STLP_STD::distance(__first, __last); 00702 this->_M_start = this->_M_end_of_storage.allocate(__n, __n); 00703 this->_M_end_of_storage._M_data = this->_M_start + __n; 00704 this->_M_finish = uninitialized_copy(__first, __last, this->_M_start); 00705 } 00706 #endif /* _STLP_MEMBER_TEMPLATES */ 00707 }; 00708 00709 #if defined (vector) 00710 # undef vector 00711 _STLP_MOVE_TO_STD_NAMESPACE 00712 #endif 00713 00714 _STLP_END_NAMESPACE 00715 00716 #if !defined (_STLP_LINK_TIME_INSTANTIATION) 00717 # include <stl/_vector.c> 00718 #endif 00719 00720 #if defined (_STLP_USE_PTR_SPECIALIZATIONS) 00721 # include <stl/pointers/_vector.h> 00722 #endif 00723 00724 //We define the bool specialization before the debug interfave 00725 //to benefit of the debug version of vector even for the bool 00726 //specialization. 00727 #if !defined (_STLP_NO_BOOL) || !defined (_STLP_NO_EXTENSIONS) 00728 # if !defined (_STLP_INTERNAL_BVECTOR_H) 00729 # include <stl/_bvector.h> 00730 # endif 00731 #endif 00732 00733 #if defined (_STLP_DEBUG) 00734 # include <stl/debug/_vector.h> 00735 #endif 00736 00737 _STLP_BEGIN_NAMESPACE 00738 00739 #if !defined (_STLP_NO_BOOL) && !defined (_STLP_NO_EXTENSIONS) 00740 // This typedef is non-standard. It is provided for backward compatibility. 00741 typedef vector<bool, allocator<bool> > bit_vector; 00742 #endif 00743 00744 #define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc> 00745 #define _STLP_TEMPLATE_CONTAINER vector<_Tp, _Alloc> 00746 #include <stl/_relops_cont.h> 00747 #undef _STLP_TEMPLATE_CONTAINER 00748 #undef _STLP_TEMPLATE_HEADER 00749 00750 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) 00751 # if !defined (_STLP_NO_MOVE_SEMANTIC) 00752 template <class _Tp, class _Alloc> 00753 struct __move_traits<vector<_Tp, _Alloc> > { 00754 typedef __true_type implemented; 00755 typedef typename __move_traits<_Alloc>::complete complete; 00756 }; 00757 # endif 00758 00759 # if !defined (_STLP_DEBUG) 00760 template <class _Tp, class _Alloc> 00761 struct _DefaultZeroValue<vector<_Tp, _Alloc> > 00762 { typedef typename __type_traits<_Alloc>::has_trivial_default_constructor _Ret; }; 00763 # endif 00764 00765 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */ 00766 00767 _STLP_END_NAMESPACE 00768 00769 #endif /* _STLP_VECTOR_H */ 00770 00771 // Local Variables: 00772 // mode:C++ 00773 // End: Generated on Wed May 23 2012 04:27:46 for ReactOS by
1.7.6.1
|