/project/jni/stlport/stlport/stl/_vector.h

https://github.com/aichunyu/FFPlayer · C Header · 735 lines · 582 code · 95 blank · 58 comment · 55 complexity · 160cdef55663a73499a88e7b8b317f9c MD5 · raw file

  1. /*
  2. *
  3. * Copyright (c) 1994
  4. * Hewlett-Packard Company
  5. *
  6. * Copyright (c) 1996,1997
  7. * Silicon Graphics Computer Systems, Inc.
  8. *
  9. * Copyright (c) 1997
  10. * Moscow Center for SPARC Technology
  11. *
  12. * Copyright (c) 1999
  13. * Boris Fomitchev
  14. *
  15. * This material is provided "as is", with absolutely no warranty expressed
  16. * or implied. Any use is at your own risk.
  17. *
  18. * Permission to use or copy this software for any purpose is hereby granted
  19. * without fee, provided the above notices are retained on all copies.
  20. * Permission to modify the code and to distribute modified code is granted,
  21. * provided the above notices are retained, and a notice that the code was
  22. * modified is included with the above copyright notice.
  23. *
  24. */
  25. /* NOTE: This is an internal header file, included by other STL headers.
  26. * You should not attempt to use it directly.
  27. */
  28. #ifndef _STLP_INTERNAL_VECTOR_H
  29. #define _STLP_INTERNAL_VECTOR_H
  30. #ifndef _STLP_INTERNAL_ALGOBASE_H
  31. # include <stl/_algobase.h>
  32. #endif
  33. #ifndef _STLP_INTERNAL_ALLOC_H
  34. # include <stl/_alloc.h>
  35. #endif
  36. #ifndef _STLP_INTERNAL_ITERATOR_H
  37. # include <stl/_iterator.h>
  38. #endif
  39. #ifndef _STLP_INTERNAL_UNINITIALIZED_H
  40. # include <stl/_uninitialized.h>
  41. #endif
  42. _STLP_BEGIN_NAMESPACE
  43. // The vector base class serves one purpose, its constructor and
  44. // destructor allocate (but don't initialize) storage. This makes
  45. // exception safety easier.
  46. _STLP_MOVE_TO_PRIV_NAMESPACE
  47. template <class _Tp, class _Alloc>
  48. class _Vector_base {
  49. public:
  50. typedef _Vector_base<_Tp, _Alloc> _Self;
  51. _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
  52. typedef typename _Alloc_traits<_Tp, _Alloc>::allocator_type allocator_type;
  53. typedef _Tp* pointer;
  54. typedef _STLP_alloc_proxy<pointer, _Tp, allocator_type> _AllocProxy;
  55. _Vector_base(const _Alloc& __a)
  56. : _M_start(0), _M_finish(0), _M_end_of_storage(__a, 0) {}
  57. _Vector_base(size_t __n, const _Alloc& __a)
  58. : _M_start(0), _M_finish(0), _M_end_of_storage(__a, 0) {
  59. _M_start = _M_end_of_storage.allocate(__n, __n);
  60. _M_finish = _M_start;
  61. _M_end_of_storage._M_data = _M_start + __n;
  62. _STLP_MPWFIX_TRY _STLP_MPWFIX_CATCH
  63. }
  64. _Vector_base(__move_source<_Self> src)
  65. : _M_start(src.get()._M_start), _M_finish(src.get()._M_finish),
  66. _M_end_of_storage(__move_source<_AllocProxy>(src.get()._M_end_of_storage)) {
  67. //Set the source as empty:
  68. src.get()._M_finish = src.get()._M_end_of_storage._M_data = src.get()._M_start = 0;
  69. }
  70. ~_Vector_base() {
  71. if (_M_start != _STLP_DEFAULT_CONSTRUCTED(pointer))
  72. _M_end_of_storage.deallocate(_M_start, _M_end_of_storage._M_data - _M_start);
  73. }
  74. protected:
  75. void _STLP_FUNCTION_THROWS _M_throw_length_error() const;
  76. void _STLP_FUNCTION_THROWS _M_throw_out_of_range() const;
  77. pointer _M_start;
  78. pointer _M_finish;
  79. _AllocProxy _M_end_of_storage;
  80. };
  81. #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
  82. # define vector _STLP_PTR_IMPL_NAME(vector)
  83. #elif defined (_STLP_DEBUG)
  84. # define vector _STLP_NON_DBG_NAME(vector)
  85. #else
  86. _STLP_MOVE_TO_STD_NAMESPACE
  87. #endif
  88. template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
  89. class vector : protected _STLP_PRIV _Vector_base<_Tp, _Alloc>
  90. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (vector)
  91. , public __stlport_class<vector<_Tp, _Alloc> >
  92. #endif
  93. {
  94. private:
  95. typedef _STLP_PRIV _Vector_base<_Tp, _Alloc> _Base;
  96. typedef vector<_Tp, _Alloc> _Self;
  97. public:
  98. _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
  99. typedef typename _Base::allocator_type allocator_type;
  100. typedef _Tp value_type;
  101. typedef value_type* pointer;
  102. typedef const value_type* const_pointer;
  103. typedef value_type* iterator;
  104. typedef const value_type* const_iterator;
  105. typedef value_type& reference;
  106. typedef const value_type& const_reference;
  107. typedef size_t size_type;
  108. typedef ptrdiff_t difference_type;
  109. typedef random_access_iterator_tag _Iterator_category;
  110. _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
  111. allocator_type get_allocator() const
  112. { return _STLP_CONVERT_ALLOCATOR((const allocator_type&)this->_M_end_of_storage, _Tp); }
  113. private:
  114. typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _TrivialCopy;
  115. typedef typename __type_traits<_Tp>::has_trivial_copy_constructor _TrivialUCopy;
  116. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  117. typedef typename __move_traits<_Tp>::implemented _Movable;
  118. #else
  119. typedef __false_type _Movable;
  120. #endif
  121. // handles insertions on overflow
  122. void _M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __false_type& /*_Movable*/,
  123. size_type __fill_len, bool __atend);
  124. void _M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __true_type& /*_Movable*/,
  125. size_type __fill_len, bool __atend) {
  126. //We need to take care of self referencing here:
  127. if (_M_is_inside(__x)) {
  128. value_type __x_copy = __x;
  129. _M_insert_overflow_aux(__pos, __x_copy, __false_type(), __fill_len, __atend);
  130. return;
  131. }
  132. _M_insert_overflow_aux(__pos, __x, __false_type(), __fill_len, __atend);
  133. }
  134. void _M_insert_overflow(pointer __pos, const _Tp& __x, const __false_type& /*_TrivialCopy*/,
  135. size_type __fill_len, bool __atend = false)
  136. { _M_insert_overflow_aux(__pos, __x, _Movable(), __fill_len, __atend); }
  137. void _M_insert_overflow(pointer __pos, const _Tp& __x, const __true_type& /*_TrivialCopy*/,
  138. size_type __fill_len, bool __atend = false);
  139. void _M_range_check(size_type __n) const {
  140. if (__n >= size_type(this->_M_finish - this->_M_start))
  141. this->_M_throw_out_of_range();
  142. }
  143. public:
  144. iterator begin() { return this->_M_start; }
  145. const_iterator begin() const { return this->_M_start; }
  146. iterator end() { return this->_M_finish; }
  147. const_iterator end() const { return this->_M_finish; }
  148. reverse_iterator rbegin() { return reverse_iterator(end()); }
  149. const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
  150. reverse_iterator rend() { return reverse_iterator(begin()); }
  151. const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
  152. size_type size() const { return size_type(this->_M_finish - this->_M_start); }
  153. size_type max_size() const {
  154. size_type __vector_max_size = size_type(-1) / sizeof(_Tp);
  155. typename allocator_type::size_type __alloc_max_size = this->_M_end_of_storage.max_size();
  156. return (__alloc_max_size < __vector_max_size)?__alloc_max_size:__vector_max_size;
  157. }
  158. size_type capacity() const { return size_type(this->_M_end_of_storage._M_data - this->_M_start); }
  159. bool empty() const { return this->_M_start == this->_M_finish; }
  160. reference operator[](size_type __n) { return *(begin() + __n); }
  161. const_reference operator[](size_type __n) const { return *(begin() + __n); }
  162. reference front() { return *begin(); }
  163. const_reference front() const { return *begin(); }
  164. reference back() { return *(end() - 1); }
  165. const_reference back() const { return *(end() - 1); }
  166. reference at(size_type __n) { _M_range_check(__n); return (*this)[__n]; }
  167. const_reference at(size_type __n) const { _M_range_check(__n); return (*this)[__n]; }
  168. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  169. explicit vector(const allocator_type& __a = allocator_type())
  170. #else
  171. vector()
  172. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(allocator_type()) {}
  173. vector(const allocator_type& __a)
  174. #endif
  175. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__a) {}
  176. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  177. private:
  178. //We always call _M_initialize with only 1 parameter. Default parameter
  179. //is used to allow explicit instanciation of vector with types with no
  180. //default constructor.
  181. void _M_initialize(size_type __n, const _Tp& __val = _STLP_DEFAULT_CONSTRUCTED(_Tp))
  182. { this->_M_finish = _STLP_PRIV __uninitialized_init(this->_M_start, __n, __val); }
  183. public:
  184. explicit vector(size_type __n)
  185. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, allocator_type())
  186. { _M_initialize(__n); }
  187. vector(size_type __n, const _Tp& __val, const allocator_type& __a = allocator_type())
  188. #else
  189. explicit vector(size_type __n)
  190. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, allocator_type())
  191. { this->_M_finish = _STLP_PRIV __uninitialized_init(this->_M_start, __n, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
  192. vector(size_type __n, const _Tp& __val)
  193. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, allocator_type())
  194. { this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_start, __n, __val); }
  195. vector(size_type __n, const _Tp& __val, const allocator_type& __a)
  196. #endif
  197. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__n, __a)
  198. { this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_start, __n, __val); }
  199. vector(const _Self& __x)
  200. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__x.size(), __x.get_allocator())
  201. { this->_M_finish = _STLP_PRIV __ucopy_ptrs(__x.begin(), __x.end(), this->_M_start, _TrivialUCopy()); }
  202. vector(__move_source<_Self> src)
  203. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__move_source<_Base>(src.get()))
  204. {}
  205. #if defined (_STLP_MEMBER_TEMPLATES)
  206. private:
  207. template <class _Integer>
  208. void _M_initialize_aux(_Integer __n, _Integer __val,
  209. const __true_type& /*_IsIntegral*/) {
  210. size_type __real_n;
  211. this->_M_start = this->_M_end_of_storage.allocate(__n, __real_n);
  212. this->_M_end_of_storage._M_data = this->_M_start + __real_n;
  213. this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_start, __n, __val);
  214. }
  215. template <class _InputIterator>
  216. void _M_initialize_aux(_InputIterator __first, _InputIterator __last,
  217. const __false_type& /*_IsIntegral*/)
  218. { _M_range_initialize(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator)); }
  219. public:
  220. // Check whether it's an integral type. If so, it's not an iterator.
  221. template <class _InputIterator>
  222. vector(_InputIterator __first, _InputIterator __last,
  223. const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL )
  224. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__a) {
  225. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  226. _M_initialize_aux(__first, __last, _Integral());
  227. }
  228. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  229. template <class _InputIterator>
  230. vector(_InputIterator __first, _InputIterator __last)
  231. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(allocator_type()) {
  232. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  233. _M_initialize_aux(__first, __last, _Integral());
  234. }
  235. # endif /* _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS */
  236. #else /* _STLP_MEMBER_TEMPLATES */
  237. vector(const _Tp* __first, const _Tp* __last,
  238. const allocator_type& __a = allocator_type())
  239. : _STLP_PRIV _Vector_base<_Tp, _Alloc>(__last - __first, __a)
  240. { this->_M_finish = _STLP_PRIV __ucopy_ptrs(__first, __last, this->_M_start, _TrivialUCopy()); }
  241. #endif /* _STLP_MEMBER_TEMPLATES */
  242. //As the vector container is a back insert oriented container it
  243. //seems rather logical to destroy elements in reverse order.
  244. ~vector() { _STLP_STD::_Destroy_Range(rbegin(), rend()); }
  245. _Self& operator=(const _Self& __x);
  246. void reserve(size_type __n);
  247. // assign(), a generalized assignment member function. Two
  248. // versions: one that takes a count, and one that takes a range.
  249. // The range version is a member template, so we dispatch on whether
  250. // or not the type is an integer.
  251. void assign(size_type __n, const _Tp& __val) { _M_fill_assign(__n, __val); }
  252. void _M_fill_assign(size_type __n, const _Tp& __val);
  253. #if defined (_STLP_MEMBER_TEMPLATES)
  254. template <class _ForwardIter>
  255. void _M_assign_aux(_ForwardIter __first, _ForwardIter __last, const forward_iterator_tag &) {
  256. #else
  257. void assign(const_iterator __first, const_iterator __last) {
  258. typedef const_iterator _ForwardIter;
  259. #endif
  260. const size_type __len = distance(__first, __last);
  261. if (__len > capacity()) {
  262. size_type __n = __len;
  263. iterator __tmp = _M_allocate_and_copy(__n, __first, __last);
  264. _M_clear();
  265. _M_set(__tmp, __tmp + __len, __tmp + __n);
  266. }
  267. else if (size() >= __len) {
  268. iterator __new_finish = copy(__first, __last, this->_M_start);
  269. _STLP_STD::_Destroy_Range(__new_finish, this->_M_finish);
  270. this->_M_finish = __new_finish;
  271. }
  272. else {
  273. _ForwardIter __mid = __first;
  274. advance(__mid, size());
  275. copy(__first, __mid, this->_M_start);
  276. this->_M_finish = uninitialized_copy(__mid, __last, this->_M_finish);
  277. }
  278. }
  279. #if defined (_STLP_MEMBER_TEMPLATES)
  280. template <class _InputIter>
  281. void _M_assign_aux(_InputIter __first, _InputIter __last,
  282. const input_iterator_tag &) {
  283. iterator __cur = begin();
  284. for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
  285. *__cur = *__first;
  286. if (__first == __last)
  287. erase(__cur, end());
  288. else
  289. insert(end(), __first, __last);
  290. }
  291. template <class _Integer>
  292. void _M_assign_dispatch(_Integer __n, _Integer __val,
  293. const __true_type& /*_IsIntegral*/)
  294. { _M_fill_assign(__n, __val); }
  295. template <class _InputIter>
  296. void _M_assign_dispatch(_InputIter __first, _InputIter __last,
  297. const __false_type& /*_IsIntegral*/)
  298. { _M_assign_aux(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); }
  299. template <class _InputIterator>
  300. void assign(_InputIterator __first, _InputIterator __last) {
  301. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  302. _M_assign_dispatch(__first, __last, _Integral());
  303. }
  304. #endif /* _STLP_MEMBER_TEMPLATES */
  305. #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
  306. void push_back(const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
  307. #else
  308. void push_back(const _Tp& __x) {
  309. #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  310. if (this->_M_finish != this->_M_end_of_storage._M_data) {
  311. _Copy_Construct(this->_M_finish, __x);
  312. ++this->_M_finish;
  313. }
  314. else
  315. _M_insert_overflow(this->_M_finish, __x, _TrivialCopy(), 1UL, true);
  316. }
  317. #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
  318. iterator insert(iterator __pos, const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp));
  319. #else
  320. iterator insert(iterator __pos, const _Tp& __x);
  321. #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  322. #if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
  323. void push_back() { push_back(_STLP_DEFAULT_CONSTRUCTED(_Tp)); }
  324. iterator insert(iterator __pos) { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
  325. #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  326. void swap(_Self& __x) {
  327. _STLP_STD::swap(this->_M_start, __x._M_start);
  328. _STLP_STD::swap(this->_M_finish, __x._M_finish);
  329. this->_M_end_of_storage.swap(__x._M_end_of_storage);
  330. }
  331. private:
  332. void _M_fill_insert_aux (iterator __pos, size_type __n, const _Tp& __x, const __true_type& /*_Movable*/);
  333. void _M_fill_insert_aux (iterator __pos, size_type __n, const _Tp& __x, const __false_type& /*_Movable*/);
  334. void _M_fill_insert (iterator __pos, size_type __n, const _Tp& __x);
  335. bool _M_is_inside(const value_type& __x) const {
  336. return (&__x >= this->_M_start && &__x < this->_M_finish);
  337. }
  338. #if defined (_STLP_MEMBER_TEMPLATES)
  339. template <class _ForwardIterator>
  340. void _M_range_insert_realloc(iterator __pos,
  341. _ForwardIterator __first, _ForwardIterator __last,
  342. #else
  343. void _M_range_insert_realloc(iterator __pos,
  344. const_iterator __first, const_iterator __last,
  345. #endif /* _STLP_MEMBER_TEMPLATES */
  346. size_type __n) {
  347. const size_type __old_size = size();
  348. size_type __len = __old_size + (max)(__old_size, __n);
  349. pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
  350. pointer __new_finish = __new_start;
  351. _STLP_TRY {
  352. __new_finish = _STLP_PRIV __uninitialized_move(this->_M_start, __pos, __new_start, _TrivialUCopy(), _Movable());
  353. __new_finish = uninitialized_copy(__first, __last, __new_finish);
  354. __new_finish = _STLP_PRIV __uninitialized_move(__pos, this->_M_finish, __new_finish, _TrivialUCopy(), _Movable());
  355. }
  356. _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
  357. this->_M_end_of_storage.deallocate(__new_start,__len)))
  358. _M_clear_after_move();
  359. _M_set(__new_start, __new_finish, __new_start + __len);
  360. }
  361. #if defined (_STLP_MEMBER_TEMPLATES)
  362. template <class _ForwardIterator>
  363. void _M_range_insert_aux(iterator __pos,
  364. _ForwardIterator __first, _ForwardIterator __last,
  365. #else
  366. void _M_range_insert_aux(iterator __pos,
  367. const_iterator __first, const_iterator __last,
  368. #endif /* _STLP_MEMBER_TEMPLATES */
  369. size_type __n, const __true_type& /*_Movable*/) {
  370. iterator __src = this->_M_finish - 1;
  371. iterator __dst = __src + __n;
  372. for (; __src >= __pos; --__dst, --__src) {
  373. _STLP_STD::_Move_Construct(__dst, *__src);
  374. _STLP_STD::_Destroy_Moved(__src);
  375. }
  376. uninitialized_copy(__first, __last, __pos);
  377. this->_M_finish += __n;
  378. }
  379. #if defined (_STLP_MEMBER_TEMPLATES)
  380. template <class _ForwardIterator>
  381. void _M_range_insert_aux(iterator __pos,
  382. _ForwardIterator __first, _ForwardIterator __last,
  383. #else
  384. void _M_range_insert_aux(iterator __pos,
  385. const_iterator __first, const_iterator __last,
  386. #endif /* _STLP_MEMBER_TEMPLATES */
  387. size_type __n, const __false_type& /*_Movable*/) {
  388. const size_type __elems_after = this->_M_finish - __pos;
  389. pointer __old_finish = this->_M_finish;
  390. if (__elems_after > __n) {
  391. _STLP_PRIV __ucopy_ptrs(this->_M_finish - __n, this->_M_finish, this->_M_finish, _TrivialUCopy());
  392. this->_M_finish += __n;
  393. _STLP_PRIV __copy_backward_ptrs(__pos, __old_finish - __n, __old_finish, _TrivialCopy());
  394. copy(__first, __last, __pos);
  395. }
  396. else {
  397. #if defined ( _STLP_MEMBER_TEMPLATES )
  398. _ForwardIterator __mid = __first;
  399. advance(__mid, __elems_after);
  400. #else
  401. const_pointer __mid = __first + __elems_after;
  402. #endif
  403. uninitialized_copy(__mid, __last, this->_M_finish);
  404. this->_M_finish += __n - __elems_after;
  405. _STLP_PRIV __ucopy_ptrs(__pos, __old_finish, this->_M_finish, _TrivialUCopy());
  406. this->_M_finish += __elems_after;
  407. copy(__first, __mid, __pos);
  408. } /* elems_after */
  409. }
  410. #if defined (_STLP_MEMBER_TEMPLATES)
  411. template <class _Integer>
  412. void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
  413. const __true_type&)
  414. { _M_fill_insert(__pos, (size_type) __n, (_Tp) __val); }
  415. template <class _InputIterator>
  416. void _M_insert_dispatch(iterator __pos,
  417. _InputIterator __first, _InputIterator __last,
  418. const __false_type&)
  419. { _M_range_insert(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator)); }
  420. public:
  421. // Check whether it's an integral type. If so, it's not an iterator.
  422. template <class _InputIterator>
  423. void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
  424. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  425. _M_insert_dispatch(__pos, __first, __last, _Integral());
  426. }
  427. private:
  428. template <class _InputIterator>
  429. void _M_range_insert(iterator __pos,
  430. _InputIterator __first, _InputIterator __last,
  431. const input_iterator_tag &) {
  432. for ( ; __first != __last; ++__first) {
  433. __pos = insert(__pos, *__first);
  434. ++__pos;
  435. }
  436. }
  437. template <class _ForwardIterator>
  438. void _M_range_insert(iterator __pos,
  439. _ForwardIterator __first, _ForwardIterator __last,
  440. const forward_iterator_tag &) {
  441. #else /* _STLP_MEMBER_TEMPLATES */
  442. public:
  443. void insert(iterator __pos,
  444. const_iterator __first, const_iterator __last) {
  445. #endif /* _STLP_MEMBER_TEMPLATES */
  446. /* This method do not check self referencing.
  447. * Standard forbids it, checked by the debug mode.
  448. */
  449. if (__first != __last) {
  450. size_type __n = distance(__first, __last);
  451. if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n) {
  452. _M_range_insert_aux(__pos, __first, __last, __n, _Movable());
  453. }
  454. else {
  455. _M_range_insert_realloc(__pos, __first, __last, __n);
  456. }
  457. }
  458. }
  459. public:
  460. void insert (iterator __pos, size_type __n, const _Tp& __x)
  461. { _M_fill_insert(__pos, __n, __x); }
  462. void pop_back() {
  463. --this->_M_finish;
  464. _STLP_STD::_Destroy(this->_M_finish);
  465. }
  466. private:
  467. iterator _M_erase(iterator __pos, const __true_type& /*_Movable*/) {
  468. _STLP_STD::_Destroy(__pos);
  469. iterator __dst = __pos, __src = __dst + 1;
  470. iterator __end = end();
  471. for (; __src != __end; ++__dst, ++__src) {
  472. _STLP_STD::_Move_Construct(__dst, *__src);
  473. _STLP_STD::_Destroy_Moved(__src);
  474. }
  475. this->_M_finish = __dst;
  476. return __pos;
  477. }
  478. iterator _M_erase(iterator __pos, const __false_type& /*_Movable*/) {
  479. if (__pos + 1 != end())
  480. _STLP_PRIV __copy_ptrs(__pos + 1, this->_M_finish, __pos, _TrivialCopy());
  481. --this->_M_finish;
  482. _STLP_STD::_Destroy(this->_M_finish);
  483. return __pos;
  484. }
  485. iterator _M_erase(iterator __first, iterator __last, const __true_type& /*_Movable*/) {
  486. iterator __dst = __first, __src = __last;
  487. iterator __end = end();
  488. for (; __dst != __last && __src != __end; ++__dst, ++__src) {
  489. _STLP_STD::_Destroy(__dst);
  490. _STLP_STD::_Move_Construct(__dst, *__src);
  491. }
  492. if (__dst != __last) {
  493. //There is more elements to erase than element to move:
  494. _STLP_STD::_Destroy_Range(__dst, __last);
  495. _STLP_STD::_Destroy_Moved_Range(__last, __end);
  496. }
  497. else {
  498. //There is more element to move than element to erase:
  499. for (; __src != __end; ++__dst, ++__src) {
  500. _STLP_STD::_Destroy_Moved(__dst);
  501. _STLP_STD::_Move_Construct(__dst, *__src);
  502. }
  503. _STLP_STD::_Destroy_Moved_Range(__dst, __end);
  504. }
  505. this->_M_finish = __dst;
  506. return __first;
  507. }
  508. iterator _M_erase(iterator __first, iterator __last, const __false_type& /*_Movable*/) {
  509. pointer __i = _STLP_PRIV __copy_ptrs(__last, this->_M_finish, __first, _TrivialCopy());
  510. _STLP_STD::_Destroy_Range(__i, this->_M_finish);
  511. this->_M_finish = __i;
  512. return __first;
  513. }
  514. public:
  515. iterator erase(iterator __pos) {
  516. return _M_erase(__pos, _Movable());
  517. }
  518. iterator erase(iterator __first, iterator __last) {
  519. if (__first == __last)
  520. return __first;
  521. return _M_erase(__first, __last, _Movable());
  522. }
  523. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  524. void resize(size_type __new_size, const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
  525. #else
  526. void resize(size_type __new_size, const _Tp& __x) {
  527. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  528. if (__new_size < size())
  529. erase(begin() + __new_size, end());
  530. else
  531. insert(end(), __new_size - size(), __x);
  532. }
  533. #if defined (_STLP_DONT_SUP_DFLT_PARAM)
  534. void resize(size_type __new_size) { resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
  535. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  536. void clear() {
  537. erase(begin(), end());
  538. }
  539. private:
  540. void _M_clear() {
  541. _STLP_STD::_Destroy_Range(rbegin(), rend());
  542. this->_M_end_of_storage.deallocate(this->_M_start, this->_M_end_of_storage._M_data - this->_M_start);
  543. }
  544. void _M_clear_after_move() {
  545. _STLP_STD::_Destroy_Moved_Range(rbegin(), rend());
  546. this->_M_end_of_storage.deallocate(this->_M_start, this->_M_end_of_storage._M_data - this->_M_start);
  547. }
  548. void _M_set(pointer __s, pointer __f, pointer __e) {
  549. this->_M_start = __s;
  550. this->_M_finish = __f;
  551. this->_M_end_of_storage._M_data = __e;
  552. }
  553. #if defined (_STLP_MEMBER_TEMPLATES)
  554. template <class _ForwardIterator>
  555. pointer _M_allocate_and_copy(size_type& __n,
  556. _ForwardIterator __first, _ForwardIterator __last)
  557. #else /* _STLP_MEMBER_TEMPLATES */
  558. pointer _M_allocate_and_copy(size_type& __n,
  559. const_pointer __first, const_pointer __last)
  560. #endif /* _STLP_MEMBER_TEMPLATES */
  561. {
  562. pointer __result = this->_M_end_of_storage.allocate(__n, __n);
  563. _STLP_TRY {
  564. uninitialized_copy(__first, __last, __result);
  565. return __result;
  566. }
  567. _STLP_UNWIND(this->_M_end_of_storage.deallocate(__result, __n))
  568. _STLP_RET_AFTER_THROW(__result)
  569. }
  570. #if defined (_STLP_MEMBER_TEMPLATES)
  571. template <class _InputIterator>
  572. void _M_range_initialize(_InputIterator __first, _InputIterator __last,
  573. const input_iterator_tag &) {
  574. for ( ; __first != __last; ++__first)
  575. push_back(*__first);
  576. }
  577. // This function is only called by the constructor.
  578. template <class _ForwardIterator>
  579. void _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
  580. const forward_iterator_tag &) {
  581. size_type __n = distance(__first, __last);
  582. this->_M_start = this->_M_end_of_storage.allocate(__n, __n);
  583. this->_M_end_of_storage._M_data = this->_M_start + __n;
  584. this->_M_finish = uninitialized_copy(__first, __last, this->_M_start);
  585. }
  586. #endif /* _STLP_MEMBER_TEMPLATES */
  587. };
  588. #if defined (vector)
  589. # undef vector
  590. _STLP_MOVE_TO_STD_NAMESPACE
  591. #endif
  592. _STLP_END_NAMESPACE
  593. #if !defined (_STLP_LINK_TIME_INSTANTIATION)
  594. # include <stl/_vector.c>
  595. #endif
  596. #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
  597. # include <stl/pointers/_vector.h>
  598. #endif
  599. //We define the bool specialization before the debug interfave
  600. //to benefit of the debug version of vector even for the bool
  601. //specialization.
  602. #if !defined (_STLP_NO_BOOL) || !defined (_STLP_NO_EXTENSIONS)
  603. # if !defined (_STLP_INTERNAL_BVECTOR_H)
  604. # include <stl/_bvector.h>
  605. # endif
  606. #endif
  607. #if defined (_STLP_DEBUG)
  608. # include <stl/debug/_vector.h>
  609. #endif
  610. _STLP_BEGIN_NAMESPACE
  611. #if !defined (_STLP_NO_BOOL) && !defined (_STLP_NO_EXTENSIONS)
  612. // This typedef is non-standard. It is provided for backward compatibility.
  613. typedef vector<bool, allocator<bool> > bit_vector;
  614. #endif
  615. #define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc>
  616. #define _STLP_TEMPLATE_CONTAINER vector<_Tp, _Alloc>
  617. #include <stl/_relops_cont.h>
  618. #undef _STLP_TEMPLATE_CONTAINER
  619. #undef _STLP_TEMPLATE_HEADER
  620. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  621. template <class _Tp, class _Alloc>
  622. struct __move_traits<vector<_Tp, _Alloc> > {
  623. typedef __stlp_movable implemented;
  624. typedef typename __move_traits<_Alloc>::complete complete;
  625. #if defined (__BORLANDC__) && (__BORLANDC__ < 0x560)
  626. // disable incorrect "dependent type qualifier" error
  627. typedef __false_type _Ret;
  628. #endif
  629. };
  630. # if !defined (_STLP_DEBUG)
  631. template <class _Tp, class _Alloc>
  632. struct _DefaultZeroValue<vector<_Tp, _Alloc> >
  633. { typedef typename __type_traits<_Alloc>::has_trivial_default_constructor _Ret; };
  634. # endif
  635. #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
  636. _STLP_END_NAMESPACE
  637. #endif /* _STLP_VECTOR_H */
  638. // Local Variables:
  639. // mode:C++
  640. // End: