4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
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.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_UNINITIALIZED_H
31 #define _STLP_INTERNAL_UNINITIALIZED_H
33 # ifndef _STLP_CSTRING
37 # ifndef _STLP_INTERNAL_ALGOBASE_H
38 # include <stl/_algobase.h>
41 # ifndef _STLP_INTERNAL_CONSTRUCT_H
42 # include <stl/_construct.h>
49 // Valid if copy construction is equivalent to assignment, and if the
50 // destructor is trivial.
51 template <class _InputIter, class _ForwardIter>
53 __uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result,
55 return __copy_aux(__first, __last, __result, _BothPtrType< _InputIter, _ForwardIter> :: _Ret());
58 template <class _InputIter, class _ForwardIter>
61 __uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result,
64 _STLP_LEAVE_VOLATILE _ForwardIter __cur = __result;
66 for ( ; __first != __last; ++__first, ++__cur)
67 _Construct(&*__cur, *__first);
70 _STLP_UNWIND (_STLP_STD::_Destroy(__result, __cur));
74 template <class _InputIter, class _ForwardIter>
76 uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result) {
77 return __uninitialized_copy(__first, __last, __result, _IS_POD_ITER(__result, _ForwardIter));
81 uninitialized_copy(const char* __first, const char* __last, char* __result) {
82 return (char*)__copy_trivial (__first, __last, __result);
85 # ifdef _STLP_HAS_WCHAR_T // dwa 8/15/97
87 uninitialized_copy(const wchar_t* __first, const wchar_t* __last, wchar_t* __result) {
88 return (wchar_t*)__copy_trivial (__first, __last, __result);
90 # endif /* _STLP_HAS_WCHAR_T */
92 # ifndef _STLP_NO_EXTENSIONS
93 // uninitialized_copy_n (not part of the C++ standard)
95 template <class _InputIter, class _Size, class _ForwardIter>
97 pair<_InputIter, _ForwardIter>
98 __uninitialized_copy_n(_InputIter __first, _Size __count,
99 _ForwardIter __result,
100 const input_iterator_tag &)
102 _STLP_LEAVE_VOLATILE _ForwardIter __cur = __result;
104 for ( ; __count > 0 ; --__count, ++__first, ++__cur)
105 _Construct(&*__cur, *__first);
106 // return pair<_InputIter, _ForwardIter>(__first, __cur);
108 _STLP_UNWIND(_STLP_STD::_Destroy(__result, __cur));
110 return pair<_InputIter, _ForwardIter>(__first, __cur);
114 # if defined(_STLP_NONTEMPL_BASE_MATCH_BUG)
115 template <class _InputIterator, class _Size, class _ForwardIterator>
116 inline pair<_InputIterator, _ForwardIterator>
117 __uninitialized_copy_n(_InputIterator __first, _Size __count,
118 _ForwardIterator __result,
119 const forward_iterator_tag &) {
120 return __uninitialized_copy_n(__first, __count, __result, input_iterator_tag());
123 template <class _InputIterator, class _Size, class _ForwardIterator>
124 inline pair<_InputIterator, _ForwardIterator>
125 __uninitialized_copy_n(_InputIterator __first, _Size __count,
126 _ForwardIterator __result,
127 const bidirectional_iterator_tag &) {
128 return __uninitialized_copy_n(__first, __count, __result, input_iterator_tag());
133 template <class _RandomAccessIter, class _Size, class _ForwardIter>
134 inline pair<_RandomAccessIter, _ForwardIter>
135 __uninitialized_copy_n(_RandomAccessIter __first, _Size __count, _ForwardIter __result, const random_access_iterator_tag &) {
136 _RandomAccessIter __last = __first + __count;
137 return pair<_RandomAccessIter, _ForwardIter>( __last, __uninitialized_copy(__first, __last, __result,
138 _IS_POD_ITER(__result, _ForwardIter)));
141 // this is used internally in <rope> , which is extension itself.
142 template <class _InputIter, class _Size, class _ForwardIter>
143 inline pair<_InputIter, _ForwardIter>
144 uninitialized_copy_n(_InputIter __first, _Size __count,
145 _ForwardIter __result) {
146 return __uninitialized_copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
148 # endif /* _STLP_NO_EXTENSIONS */
150 // Valid if copy construction is equivalent to assignment, and if the
151 // destructor is trivial.
152 template <class _ForwardIter, class _Tp>
154 __uninitialized_fill(_ForwardIter __first, _ForwardIter __last,
155 const _Tp& __x, const __true_type&) {
156 _STLP_STD::fill(__first, __last, __x);
159 template <class _ForwardIter, class _Tp>
162 __uninitialized_fill(_ForwardIter __first, _ForwardIter __last,
163 const _Tp& __x, const __false_type&)
165 _STLP_LEAVE_VOLATILE _ForwardIter __cur = __first;
167 for ( ; __cur != __last; ++__cur)
168 _Construct(&*__cur, __x);
170 _STLP_UNWIND(_STLP_STD::_Destroy(__first, __cur));
173 template <class _ForwardIter, class _Tp>
174 inline void uninitialized_fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __x) {
175 __uninitialized_fill(__first, __last, __x, _IS_POD_ITER(__first, _ForwardIter));
178 // Valid if copy construction is equivalent to assignment, and if the
179 // destructor is trivial.
180 template <class _ForwardIter, class _Size, class _Tp>
182 __uninitialized_fill_n(_ForwardIter __first, _Size __n,
183 const _Tp& __x, const __true_type&) {
184 return _STLP_STD::fill_n(__first, __n, __x);
187 template <class _ForwardIter, class _Size, class _Tp>
190 __uninitialized_fill_n(_ForwardIter __first, _Size __n,
191 const _Tp& __x, const __false_type&)
193 _STLP_LEAVE_VOLATILE _ForwardIter __cur = __first;
195 for ( ; __n > 0; --__n, ++__cur)
196 _Construct(&*__cur, __x);
199 _STLP_UNWIND(_STLP_STD::_Destroy(__first, __cur));
200 // # ifdef _STLP_THROW_RETURN_BUG
205 template <class _ForwardIter, class _Size, class _Tp>
207 uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x) {
208 return __uninitialized_fill_n(__first, __n, __x, _IS_POD_ITER(__first, _ForwardIter));
211 // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill,
212 // __uninitialized_fill_copy.
214 // __uninitialized_copy_copy
215 // Copies [first1, last1) into [result, result + (last1 - first1)), and
216 // copies [first2, last2) into
217 // [result, result + (last1 - first1) + (last2 - first2)).
219 template <class _InputIter1, class _InputIter2, class _ForwardIter>
221 __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
222 _InputIter2 __first2, _InputIter2 __last2,
223 _ForwardIter __result, __true_type)
225 return __uninitialized_copy(__first2, __last2,
226 __uninitialized_copy(__first1, __last1, __result, __true_type()), __true_type());
229 template <class _InputIter1, class _InputIter2, class _ForwardIter>
232 __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
233 _InputIter2 __first2, _InputIter2 __last2,
234 _ForwardIter __result, __false_type)
236 _STLP_LEAVE_VOLATILE _ForwardIter __mid = __uninitialized_copy(__first1, __last1, __result, _IS_POD_ITER(__result, _ForwardIter));
239 return __uninitialized_copy(__first2, __last2, __mid , _IS_POD_ITER(__result, _ForwardIter));
241 _STLP_UNWIND (_STLP_STD::_Destroy(__result, __mid));
242 # ifdef _STLP_THROW_RETURN_BUG
247 // __uninitialized_fill_copy
248 // Fills [result, mid) with x, and copies [first, last) into
249 // [mid, mid + (last - first)).
250 template <class _ForwardIter, class _Tp, class _InputIter>
253 __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid, const _Tp& __x,
254 _InputIter __first, _InputIter __last)
256 typedef typename __type_traits<_Tp>::is_POD_type _I_POD;
257 __uninitialized_fill(__result, __mid, __x, _I_POD());
259 return __uninitialized_copy(__first, __last, __mid, _I_POD());
261 _STLP_UNWIND (_STLP_STD::_Destroy(__result, __mid));
262 # ifdef _STLP_THROW_RETURN_BUG
267 // __uninitialized_copy_fill
268 // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
269 // fills [first2 + (last1 - first1), last2) with x.
270 template <class _InputIter, class _ForwardIter, class _Tp>
273 __uninitialized_copy_fill(_InputIter __first1, _InputIter __last1,
274 _ForwardIter __first2, _ForwardIter __last2,
277 typedef typename __type_traits<_Tp>::is_POD_type _I_POD;
278 _ForwardIter __mid2 = __uninitialized_copy(__first1, __last1, __first2, _I_POD());
280 __uninitialized_fill(__mid2, __last2, __x, _I_POD());
282 _STLP_UNWIND(_STLP_STD::_Destroy(__first2, __mid2));
287 #endif /* _STLP_INTERNAL_UNINITIALIZED_H */