5 * This material is provided "as is", with absolutely no warranty expressed
6 * or implied. Any use is at your own risk.
8 * Permission to use or copy this software for any purpose is hereby granted
9 * without fee, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
16 /* NOTE: This is an internal header file, included by other STL headers.
17 * You should not attempt to use it directly.
20 #ifndef _STLP_SPECIALIZED_VECTOR_H
21 #define _STLP_SPECIALIZED_VECTOR_H
23 #ifndef _STLP_POINTERS_SPEC_TOOLS_H
24 # include <stl/pointers/_tools.h>
29 #define VECTOR_IMPL _STLP_PTR_IMPL_NAME(vector)
31 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
32 _STLP_EXPORT_TEMPLATE_CLASS _STLP_PRIV _Vector_base<void*,allocator<void*> >;
33 _STLP_EXPORT_TEMPLATE_CLASS _STLP_PRIV VECTOR_IMPL<void*, allocator<void*> >;
36 #if defined (_STLP_DEBUG)
37 # define vector _STLP_NON_DBG_NAME(vector)
38 _STLP_MOVE_TO_PRIV_NAMESPACE
41 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
43 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (vector)
44 : public __stlport_class<vector<_Tp, _Alloc> >
47 /* In the vector implementation iterators are pointer which give a number
48 * of opportunities for optimization. To not break those optimizations
49 * iterators passed to template should not be wrapped for casting purpose.
50 * So vector implementation will always use a qualified void pointer type and
51 * won't use iterator wrapping.
53 typedef typename _STLP_PRIV _StorageType<_Tp>::_QualifiedType _StorageType;
54 typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc;
55 typedef _STLP_PRIV VECTOR_IMPL<_StorageType, _StorageTypeAlloc> _Base;
56 typedef vector<_Tp, _Alloc> _Self;
58 typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits;
61 typedef _Tp value_type;
62 typedef value_type* pointer;
63 typedef const value_type* const_pointer;
64 typedef value_type* iterator;
65 typedef const value_type* const_iterator;
66 typedef value_type& reference;
67 typedef const value_type& const_reference;
68 typedef size_t size_type;
69 typedef ptrdiff_t difference_type;
70 typedef random_access_iterator_tag _Iterator_category;
72 _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
73 _STLP_FORCE_ALLOCATORS(value_type, _Alloc)
74 typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type;
76 allocator_type get_allocator() const
77 { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); }
79 iterator begin() { return cast_traits::to_value_type_ptr(_M_impl.begin()); }
80 const_iterator begin() const { return cast_traits::to_value_type_cptr(_M_impl.begin()); }
81 iterator end() { return cast_traits::to_value_type_ptr(_M_impl.end()); }
82 const_iterator end() const { return cast_traits::to_value_type_cptr(_M_impl.end()); }
84 reverse_iterator rbegin() { return reverse_iterator(end()); }
85 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
86 reverse_iterator rend() { return reverse_iterator(begin()); }
87 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
89 size_type size() const { return _M_impl.size(); }
90 size_type max_size() const { return _M_impl.max_size(); }
92 size_type capacity() const { return _M_impl.capacity(); }
93 bool empty() const { return _M_impl.empty(); }
95 reference operator[](size_type __n) { return cast_traits::to_value_type_ref(_M_impl[__n]); }
96 const_reference operator[](size_type __n) const { return cast_traits::to_value_type_cref(_M_impl[__n]); }
98 reference front() { return cast_traits::to_value_type_ref(_M_impl.front()); }
99 const_reference front() const { return cast_traits::to_value_type_cref(_M_impl.front()); }
100 reference back() { return cast_traits::to_value_type_ref(_M_impl.back()); }
101 const_reference back() const { return cast_traits::to_value_type_cref(_M_impl.back()); }
103 reference at(size_type __n) { return cast_traits::to_value_type_ref(_M_impl.at(__n)); }
104 const_reference at(size_type __n) const { return cast_traits::to_value_type_cref(_M_impl.at(__n)); }
106 explicit vector(const allocator_type& __a = allocator_type())
107 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
109 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
110 explicit vector(size_type __n, const value_type& __val = _STLP_DEFAULT_CONSTRUCTED(value_type),
112 vector(size_type __n, const value_type& __val,
113 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
114 const allocator_type& __a = allocator_type())
115 : _M_impl(__n, cast_traits::to_storage_type_cref(__val),
116 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
118 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
119 explicit vector(size_type __n)
120 : _M_impl(__n, allocator_type() ) {}
121 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
123 vector(const _Self& __x)
124 : _M_impl(__x._M_impl) {}
126 explicit vector(__move_source<_Self> src)
127 : _M_impl(__move_source<_Base>(src.get()._M_impl)) {}
129 #if defined (_STLP_MEMBER_TEMPLATES)
130 template <class _InputIterator>
131 vector(_InputIterator __first, _InputIterator __last,
132 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL )
133 : _M_impl(__first, __last,
134 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
136 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
137 template <class _InputIterator>
138 vector(_InputIterator __first, _InputIterator __last)
139 : _M_impl(__first, __last) {}
143 vector(const_iterator __first, const_iterator __last,
144 const allocator_type& __a = allocator_type())
145 : _M_impl(cast_traits::to_storage_type_cptr(__first), cast_traits::to_storage_type_cptr(__last),
146 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
147 #endif /* _STLP_MEMBER_TEMPLATES */
149 _Self& operator=(const _Self& __x) { _M_impl = __x._M_impl; return *this; }
151 void reserve(size_type __n) {_M_impl.reserve(__n);}
152 void assign(size_type __n, const value_type& __val)
153 { _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val)); }
155 #if defined (_STLP_MEMBER_TEMPLATES)
156 template <class _InputIterator>
157 void assign(_InputIterator __first, _InputIterator __last)
158 { _M_impl.assign(__first, __last); }
160 void assign(const_iterator __first, const_iterator __last) {
161 _M_impl.assign(cast_traits::to_storage_type_cptr(__first),
162 cast_traits::to_storage_type_cptr(__last));
164 #endif /* _STLP_MEMBER_TEMPLATES */
166 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
167 void push_back(const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
169 void push_back(const value_type& __x)
170 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
171 { _M_impl.push_back(cast_traits::to_storage_type_cref(__x)); }
173 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
174 iterator insert(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
176 iterator insert(iterator __pos, const value_type& __x)
177 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
178 { return cast_traits::to_value_type_ptr(_M_impl.insert(cast_traits::to_storage_type_ptr(__pos),
179 cast_traits::to_storage_type_cref(__x))); }
181 #if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
182 void push_back() { _M_impl.push_back(); }
183 iterator insert(iterator __pos)
184 { return _M_impl.insert(cast_traits::to_storage_type_ptr(__pos)); }
185 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
187 void swap(_Self& __x) { _M_impl.swap(__x._M_impl); }
189 #if defined (_STLP_MEMBER_TEMPLATES)
190 template <class _InputIterator>
191 void insert(iterator __pos, _InputIterator __first, _InputIterator __last)
192 { _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), __first, __last); }
194 void insert(iterator __pos, const_iterator __first, const_iterator __last) {
195 _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), cast_traits::to_storage_type_cptr(__first),
196 cast_traits::to_storage_type_cptr(__last));
200 void insert (iterator __pos, size_type __n, const value_type& __x) {
201 _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), __n, cast_traits::to_storage_type_cref(__x));
204 void pop_back() {_M_impl.pop_back();}
205 iterator erase(iterator __pos)
206 {return cast_traits::to_value_type_ptr(_M_impl.erase(cast_traits::to_storage_type_ptr(__pos)));}
207 iterator erase(iterator __first, iterator __last) {
208 return cast_traits::to_value_type_ptr(_M_impl.erase(cast_traits::to_storage_type_ptr(__first),
209 cast_traits::to_storage_type_ptr(__last)));
212 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
213 void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
215 void resize(size_type __new_size, const value_type& __x)
216 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
217 { _M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x)); }
219 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
220 void resize(size_type __new_size) { _M_impl.resize(__new_size); }
221 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
223 void clear() { _M_impl.clear(); }
231 _STLP_MOVE_TO_STD_NAMESPACE
238 #endif /* _STLP_SPECIALIZED_VECTOR_H */