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_DFL_TMPL_PARAM(_Alloc
, allocator
<_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 _STLP_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() ) {}
123 vector(const _Self
& __x
)
124 : _M_impl(__x
._M_impl
) {}
126 #if !defined (_STLP_NO_MOVE_SEMANTIC)
127 explicit vector(__move_source
<_Self
> src
)
128 : _M_impl(__move_source
<_Base
>(src
.get()._M_impl
)) {}
131 #if defined (_STLP_MEMBER_TEMPLATES)
132 template <class _InputIterator
>
133 vector(_InputIterator __first
, _InputIterator __last
,
134 const allocator_type
& __a _STLP_ALLOCATOR_TYPE_DFL
)
135 : _M_impl(__first
, __last
,
136 _STLP_CONVERT_ALLOCATOR(__a
, _StorageType
)) {}
138 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
139 template <class _InputIterator
>
140 vector(_InputIterator __first
, _InputIterator __last
)
141 : _M_impl(__first
, __last
) {}
145 vector(const_iterator __first
, const_iterator __last
,
146 const allocator_type
& __a
= allocator_type())
147 : _M_impl(cast_traits::to_storage_type_cptr(__first
), cast_traits::to_storage_type_cptr(__last
),
148 _STLP_CONVERT_ALLOCATOR(__a
, _StorageType
)) {}
149 #endif /* _STLP_MEMBER_TEMPLATES */
151 _Self
& operator=(const _Self
& __x
) { _M_impl
= __x
._M_impl
; return *this; }
153 void reserve(size_type __n
) {_M_impl
.reserve(__n
);}
154 void assign(size_type __n
, const value_type
& __val
)
155 { _M_impl
.assign(__n
, cast_traits::to_storage_type_cref(__val
)); }
157 #if defined (_STLP_MEMBER_TEMPLATES)
158 template <class _InputIterator
>
159 void assign(_InputIterator __first
, _InputIterator __last
)
160 { _M_impl
.assign(__first
, __last
); }
162 void assign(const_iterator __first
, const_iterator __last
) {
163 _M_impl
.assign(cast_traits::to_storage_type_cptr(__first
),
164 cast_traits::to_storage_type_cptr(__last
));
166 #endif /* _STLP_MEMBER_TEMPLATES */
168 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
169 void push_back(const value_type
& __x
= _STLP_DEFAULT_CONSTRUCTED(value_type
))
171 void push_back(const value_type
& __x
)
172 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
173 { _M_impl
.push_back(cast_traits::to_storage_type_cref(__x
)); }
175 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
176 iterator
insert(iterator __pos
, const value_type
& __x
= _STLP_DEFAULT_CONSTRUCTED(value_type
))
178 iterator
insert(iterator __pos
, const value_type
& __x
)
179 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
180 { return cast_traits::to_value_type_ptr(_M_impl
.insert(cast_traits::to_storage_type_ptr(__pos
),
181 cast_traits::to_storage_type_cref(__x
))); }
183 #if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
184 void push_back() { _M_impl
.push_back(); }
185 iterator
insert(iterator __pos
)
186 { return _M_impl
.insert(cast_traits::to_storage_type_ptr(__pos
)); }
187 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
189 void swap(_Self
& __x
) { _M_impl
.swap(__x
._M_impl
); }
190 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
191 void _M_swap_workaround(_Self
& __x
) { swap(__x
); }
194 #if defined (_STLP_MEMBER_TEMPLATES)
195 template <class _InputIterator
>
196 void insert(iterator __pos
, _InputIterator __first
, _InputIterator __last
)
197 { _M_impl
.insert(cast_traits::to_storage_type_ptr(__pos
), __first
, __last
); }
199 void insert(iterator __pos
, const_iterator __first
, const_iterator __last
) {
200 _M_impl
.insert(cast_traits::to_storage_type_ptr(__pos
), cast_traits::to_storage_type_cptr(__first
),
201 cast_traits::to_storage_type_cptr(__last
));
205 void insert (iterator __pos
, size_type __n
, const value_type
& __x
) {
206 _M_impl
.insert(cast_traits::to_storage_type_ptr(__pos
), __n
, cast_traits::to_storage_type_cref(__x
));
209 void pop_back() {_M_impl
.pop_back();}
210 iterator
erase(iterator __pos
)
211 {return cast_traits::to_value_type_ptr(_M_impl
.erase(cast_traits::to_storage_type_ptr(__pos
)));}
212 iterator
erase(iterator __first
, iterator __last
) {
213 return cast_traits::to_value_type_ptr(_M_impl
.erase(cast_traits::to_storage_type_ptr(__first
),
214 cast_traits::to_storage_type_ptr(__last
)));
217 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
218 void resize(size_type __new_size
, const value_type
& __x
= _STLP_DEFAULT_CONSTRUCTED(value_type
))
220 void resize(size_type __new_size
, const value_type
& __x
)
221 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
222 { _M_impl
.resize(__new_size
, cast_traits::to_storage_type_cref(__x
)); }
224 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
225 void resize(size_type __new_size
) { _M_impl
.resize(__new_size
); }
226 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
228 void clear() { _M_impl
.clear(); }
236 _STLP_MOVE_TO_STD_NAMESPACE
243 #endif /* _STLP_SPECIALIZED_VECTOR_H */