5 * Hewlett-Packard Company
7 * Copyright (c) 1996,1997
8 * Silicon Graphics Computer Systems, Inc.
11 * Moscow Center for SPARC Technology
16 * This material is provided "as is", with absolutely no warranty expressed
17 * or implied. Any use is at your own risk.
19 * Permission to use or copy this software for any purpose is hereby granted
20 * without fee, provided the above notices are retained on all copies.
21 * Permission to modify the code and to distribute modified code is granted,
22 * provided the above notices are retained, and a notice that the code was
23 * modified is included with the above copyright notice.
26 #ifndef _STLP_VECTOR_C
27 #define _STLP_VECTOR_C
29 # if !defined (_STLP_INTERNAL_VECTOR_H)
30 # include <stl/_vector.h>
33 # if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
34 # define iterator _Tp*
35 # define size_type size_t
39 # define vector __WORKAROUND_DBG_RENAME(vector)
43 template <class _Tp, class _Alloc>
45 __vector__<_Tp, _Alloc>::reserve(size_type __n) {
46 if (capacity() < __n) {
47 const size_type __old_size = size();
50 __tmp = _M_allocate_and_copy(__n, this->_M_start, this->_M_finish);
53 __tmp = this->_M_end_of_storage.allocate(__n);
55 _M_set(__tmp, __tmp + __old_size, __tmp + __n);
59 template <class _Tp, class _Alloc>
61 __vector__<_Tp, _Alloc>::_M_fill_insert(
63 size_type __n, const _Tp& __x) {
65 if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n) {
67 const size_type __elems_after = this->_M_finish - __position;
68 pointer __old_finish = this->_M_finish;
69 if (__elems_after > __n) {
70 __uninitialized_copy(this->_M_finish - __n, this->_M_finish, this->_M_finish, _IsPODType());
71 this->_M_finish += __n;
72 __copy_backward_ptrs(__position, __old_finish - __n, __old_finish, _TrivialAss());
73 _STLP_STD::fill(__position, __position + __n, __x_copy);
76 uninitialized_fill_n(this->_M_finish, __n - __elems_after, __x_copy);
77 this->_M_finish += __n - __elems_after;
78 __uninitialized_copy(__position, __old_finish, this->_M_finish, _IsPODType());
79 this->_M_finish += __elems_after;
80 _STLP_STD::fill(__position, __old_finish, __x_copy);
84 _M_insert_overflow(__position, __x, _IsPODType(), __n);
88 template <class _Tp, class _Alloc>
89 __vector__<_Tp,_Alloc>&
90 __vector__<_Tp,_Alloc>::operator=(const __vector__<_Tp, _Alloc>& __x)
93 const size_type __xlen = __x.size();
94 if (__xlen > capacity()) {
95 pointer __tmp = _M_allocate_and_copy(__xlen, (const_pointer)__x._M_start+0, (const_pointer)__x._M_finish+0);
97 this->_M_start = __tmp;
98 this->_M_end_of_storage._M_data = this->_M_start + __xlen;
100 else if (size() >= __xlen) {
101 pointer __i = __copy_ptrs((const_pointer)__x._M_start+0, (const_pointer)__x._M_finish+0, (pointer)this->_M_start, _TrivialAss());
102 _STLP_STD::_Destroy(__i, this->_M_finish);
105 __copy_ptrs((const_pointer)__x._M_start, (const_pointer)__x._M_start + size(), (pointer)this->_M_start, _TrivialAss());
106 __uninitialized_copy((const_pointer)__x._M_start + size(), (const_pointer)__x._M_finish+0, this->_M_finish, _IsPODType());
108 this->_M_finish = this->_M_start + __xlen;
113 template <class _Tp, class _Alloc>
114 void __vector__<_Tp, _Alloc>::_M_fill_assign(size_t __n, const _Tp& __val) {
115 if (__n > capacity()) {
116 __vector__<_Tp, _Alloc> __tmp(__n, __val, get_allocator());
119 else if (__n > size()) {
120 fill(begin(), end(), __val);
121 this->_M_finish = _STLP_STD::uninitialized_fill_n(this->_M_finish, __n - size(), __val);
124 erase(_STLP_STD::fill_n(begin(), __n, __val), end());
133 #endif /* _STLP_VECTOR_C */