Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_specialized.h
Go to the documentation of this file.
1// -*- C++ -*-
2
46#ifndef _RWSTD_RW_SPECIALIZED_H_INCLUDED
47#define _RWSTD_RW_SPECIALIZED_H_INCLUDED
48
49
50#ifndef _RWSTD_RW_NEW_H_INCLUDED
51# include <rw/_new.h>
52#endif // _RWSTD_RW_NEW_H_INCLUDED
53
54
55#ifndef _RWSTD_RW_ITERBASE_H_INCLUDED
56# include <rw/_iterbase.h>
57#endif // _RWSTD_RW_ITERBASE_H_INCLUDED
58
59
61
62
63#ifndef _RWSTD_NO_NONDEDUCED_CONTEXT
64# define _RWSTD_CONTAINER_SIZE_TYPE typename _Container::size_type
65#else
66# define _RWSTD_CONTAINER_SIZE_TYPE _RWSTD_SIZE_T
67#endif // _RWSTD_NO_NONDEDUCED_CONTEXT
68
69
70// returns a suggested new capacity for a container needing more space
71template <class _Container>
73__rw_new_capacity (_RWSTD_CONTAINER_SIZE_TYPE __size, const _Container*)
74{
75 typedef _RWSTD_CONTAINER_SIZE_TYPE _RWSizeT;
76
77 const _RWSizeT __ratio = _RWSizeT ( (_RWSTD_NEW_CAPACITY_RATIO << 10)
79
80 const _RWSizeT __cap = (__size >> 10) * __ratio
81 + (((__size & 0x3ff) * __ratio) >> 10);
82
83 return (__size += _RWSTD_MINIMUM_NEW_CAPACITY) > __cap ? __size : __cap;
84}
85
86#undef _RWSTD_CONTAINER_SIZE_TYPE
87
88
89#ifndef _RWSTD_NO_PART_SPEC_OVERLOAD
90
91template <class _TypeT, class _TypeU>
92inline void
93__rw_construct (_TypeT* __p, _TypeU& __val)
94{
95 ::new (_RWSTD_STATIC_CAST (void*, __p)) _TypeT (__val);
96}
97
98
99template <class _TypeT, class _TypeU>
100inline void
101__rw_construct (volatile _TypeT* __p, _TypeU& __val)
102{
103 // remove volatile before invoking operator new
104 __rw_construct (_RWSTD_CONST_CAST (_TypeT*, __p), __val);
105}
106
107#else // #ifdef _RWSTD_NO_PART_SPEC_OVERLOAD
108
109template <class _TypeT, class _TypeU>
110inline void
111__rw_construct_impl (_TypeT* __p, _TypeU& __val)
112{
113 ::new (_RWSTD_STATIC_CAST (void*, __p)) _TypeT (__val);
114}
115
116
117template <class _TypeT, class _TypeU>
118inline void
119__rw_construct (volatile _TypeT* __p, _TypeU& __val)
120{
121 // remove volatile before invoking operator new
122 __rw_construct_impl (_RWSTD_CONST_CAST (_TypeT*, __p), __val);
123}
124
125#endif // _RWSTD_NO_PART_SPEC_OVERLOAD
126
127template <class _TypeT>
128inline void
129__rw_destroy (_TypeT &__ref)
130{
131 __ref.~_TypeT ();
132}
133
134
135template <class _ForwardIterator>
136inline void
137__rw_destroy (_ForwardIterator __first, _ForwardIterator __last)
138{
139 for (; __first != __last; ++__first)
140 __rw_destroy (*__first);
141}
142
143
144#ifndef _RWSTD_NO_PTR_VALUE_TEMPLATE_OVERLOAD
145
146// for compilers that don't optimize "empty" loops
147template <class _TypeT>
148inline void __rw_destroy (_TypeT**, _TypeT**)
149{ }
150
151#endif // _RWSTD_NO_PTR_VALUE_TEMPLATE_OVERLOAD
152
153
154} // namespace __rw
155
156
158
159template <class _TypeT>
160class allocator;
161
162
163// 20.4.4.1
164template <class _InputIterator, class _ForwardIterator>
165inline _ForwardIterator
166uninitialized_copy (_InputIterator __first, _InputIterator __last,
167 _ForwardIterator __res)
168{
169 const _ForwardIterator __start = __res;
170 typedef typename iterator_traits<_ForwardIterator>::value_type _TypeT;
171
172 _TRY {
173 for (; __first != __last; ++__first, ++__res) {
174 // avoid const-qualifying ptr to prevent an HP aCC 3 bug
175 volatile void* /* const */ __ptr =
176 _RWSTD_STATIC_CAST (volatile void*, &*__res);
177 ::new (_RWSTD_CONST_CAST (void*, __ptr)) _TypeT (*__first);
178 }
179 }
180 _CATCH (...) {
181 _RW::__rw_destroy (__start, __res);
182 _RETHROW;
183 }
184
185 return __res;
186}
187
188
189#ifdef _RWSTD_ALLOCATOR
190
191// extension
192template <class _InputIterator, class _ForwardIterator, class _Allocator>
193inline _ForwardIterator
194uninitialized_copy (_InputIterator __first, _InputIterator __last,
195 _ForwardIterator __res, _Allocator &__alloc)
196{
197 _ForwardIterator __start = __res;
198
199 _TRY {
200 for (; __first != __last; ++__first, ++__res)
201 __alloc.construct (__alloc.address (*__res), *__first);
202 }
203 _CATCH (...) {
204 for (; __start != __res; ++__start)
205 __alloc.destroy (__alloc.address (*__start));
206 _RETHROW;
207 }
208
209 return __res;
210}
211
212#endif // _RWSTD_ALLOCATOR
213
214
215// 20.4.4.2
216template <class _ForwardIterator, class _TypeT>
217inline void
218uninitialized_fill (_ForwardIterator __first, _ForwardIterator __last,
219 const _TypeT& __x)
220{
221 const _ForwardIterator __start = __first;
222
223 _TRY {
224 for (; __first != __last; ++__first)
225 _RW::__rw_construct (&*__first, __x);
226 }
227 _CATCH (...) {
228 _RW::__rw_destroy (__start, __first);
229 _RETHROW;
230 }
231}
232
233
234// 20.4.4.3
235template <class _ForwardIterator, class _Size, class _TypeT>
236inline void
237uninitialized_fill_n (_ForwardIterator __first, _Size __n, const _TypeT& __x)
238{
239 const _ForwardIterator __start = __first;
240
241 _TRY {
242 for (; __n; --__n, ++__first)
243 _RW::__rw_construct (&*__first, __x);
244 }
245 _CATCH (...) {
246 _RW::__rw_destroy (__start, __first);
247 _RETHROW;
248 }
249}
250
251
252#ifdef _RWSTD_ALLOCATOR
253
254// extension
255template <class _ForwardIter, class _Size, class _TypeT, class _Allocator>
256inline void
257uninitialized_fill_n (_ForwardIter __first, _Size __n,
258 const _TypeT& __x, _Allocator& __alloc)
259{
260 _ForwardIter __start = __first;
261
262 _TRY {
263 for (; __n; --__n, ++__first)
264 __alloc.construct (__alloc.address (*__first), __x);
265 }
266 _CATCH (...) {
267 for (; __start != __first; ++__start)
268 __alloc.destroy (__alloc.address (*__start));
269 _RETHROW;
270 }
271}
272
273#else // if !defined (_RWSTD_ALLOCATOR)
274
275
276template <class _Allocator, class _TypeT>
277class allocator_interface;
278
279// Specializations for non-standard allocators. When vector calls
280// uninitialized_{copy,fill_n} with non-standard allocator, a temporary
281// instance of allocator_interface is passed to these functions. Since
282// C++ forbids temporaries to be passed as non-const references, we
283// use these specializations to pass a const reference (and we can force
284// allocator_interface members construct & destroy to be const).
285
286template <class _InputIterator, class _ForwardIterator,
287 class _Allocator, class _TypeT>
288inline _ForwardIterator
289uninitialized_copy (_InputIterator __first,
290 _InputIterator __last,
291 _ForwardIterator __res,
292 allocator_interface<_Allocator, _TypeT> &__alloc)
293{
294 _ForwardIterator __start = __res;
295
296 _TRY {
297 for (; __first != __last; ++__first, ++__res)
298 __alloc.construct (__alloc.address (*__res), *__first);
299 }
300 _CATCH (...) {
301 for (; __start != __res; ++__start)
302 __alloc.destroy (__alloc.address (*__start));
303 _RETHROW;
304 }
305
306 return __res;
307}
308
309template <class _ForwardIter, class _Size,
310 class _TypeT, class _Allocator, class _TypeU>
311inline void
312uninitialized_fill_n (_ForwardIter __first, _Size __n,
313 const _TypeT& __x,
314 allocator_interface<_Allocator, _TypeU> &__alloc)
315{
316 _ForwardIter __start = __first;
317
318 _TRY {
319 for (; __n; --__n, ++__first)
320 __alloc.construct (__alloc.address (*__first), __x);
321 }
322 _CATCH (...) {
323 for (; __start != __first; ++__start)
324 __alloc.destroy (__alloc.address (*__start));
325 _RETHROW;
326 }
327}
328
329#endif // _RWSTD_ALLOCATOR
330
331} // namespace std
332
333
334#endif // _RWSTD_RW_SPECIALIZED_H_INCLUDED
#define _RWSTD_MINIMUM_NEW_CAPACITY
Definition _defs.h:439
#define _RETHROW
Definition _defs.h:853
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_NEW_CAPACITY_RATIO
Definition _defs.h:445
#define _TRY
Definition _defs.h:850
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _CATCH(ex)
Definition _defs.h:851
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
#define _RWSTD_RATIO_DIVIDER
Definition _defs.h:435
#define _RWSTD_CONTAINER_SIZE_TYPE
Definition json.h:5363