00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #ifndef _STL_UNINITIALIZED_H
00062 #define _STL_UNINITIALIZED_H 1
00063
00064 #include <cstring>
00065
00066 namespace std
00067 {
00068
00069 template<typename _InputIterator, typename _ForwardIterator>
00070 inline _ForwardIterator
00071 __uninitialized_copy_aux(_InputIterator __first, _InputIterator __last,
00072 _ForwardIterator __result,
00073 __true_type)
00074 { return std::copy(__first, __last, __result); }
00075
00076 template<typename _InputIterator, typename _ForwardIterator>
00077 inline _ForwardIterator
00078 __uninitialized_copy_aux(_InputIterator __first, _InputIterator __last,
00079 _ForwardIterator __result,
00080 __false_type)
00081 {
00082 _ForwardIterator __cur = __result;
00083 try
00084 {
00085 for ( ; __first != __last; ++__first, ++__cur)
00086 std::_Construct(&*__cur, *__first);
00087 return __cur;
00088 }
00089 catch(...)
00090 {
00091 std::_Destroy(__result, __cur);
00092 __throw_exception_again;
00093 }
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 template<typename _InputIterator, typename _ForwardIterator>
00106 inline _ForwardIterator
00107 uninitialized_copy(_InputIterator __first, _InputIterator __last,
00108 _ForwardIterator __result)
00109 {
00110 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
00111 typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD;
00112 return std::__uninitialized_copy_aux(__first, __last, __result,
00113 _Is_POD());
00114 }
00115
00116 inline char*
00117 uninitialized_copy(const char* __first, const char* __last, char* __result)
00118 {
00119 std::memmove(__result, __first, __last - __first);
00120 return __result + (__last - __first);
00121 }
00122
00123 inline wchar_t*
00124 uninitialized_copy(const wchar_t* __first, const wchar_t* __last,
00125 wchar_t* __result)
00126 {
00127 std::memmove(__result, __first, sizeof(wchar_t) * (__last - __first));
00128 return __result + (__last - __first);
00129 }
00130
00131
00132
00133 template<typename _ForwardIterator, typename _Tp>
00134 inline void
00135 __uninitialized_fill_aux(_ForwardIterator __first,
00136 _ForwardIterator __last,
00137 const _Tp& __x, __true_type)
00138 { std::fill(__first, __last, __x); }
00139
00140 template<typename _ForwardIterator, typename _Tp>
00141 void
00142 __uninitialized_fill_aux(_ForwardIterator __first, _ForwardIterator __last,
00143 const _Tp& __x, __false_type)
00144 {
00145 _ForwardIterator __cur = __first;
00146 try
00147 {
00148 for ( ; __cur != __last; ++__cur)
00149 std::_Construct(&*__cur, __x);
00150 }
00151 catch(...)
00152 {
00153 std::_Destroy(__first, __cur);
00154 __throw_exception_again;
00155 }
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 template<typename _ForwardIterator, typename _Tp>
00168 inline void
00169 uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last,
00170 const _Tp& __x)
00171 {
00172 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
00173 typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD;
00174 std::__uninitialized_fill_aux(__first, __last, __x, _Is_POD());
00175 }
00176
00177
00178
00179 template<typename _ForwardIterator, typename _Size, typename _Tp>
00180 inline _ForwardIterator
00181 __uninitialized_fill_n_aux(_ForwardIterator __first, _Size __n,
00182 const _Tp& __x, __true_type)
00183 { return std::fill_n(__first, __n, __x); }
00184
00185 template<typename _ForwardIterator, typename _Size, typename _Tp>
00186 _ForwardIterator
00187 __uninitialized_fill_n_aux(_ForwardIterator __first, _Size __n,
00188 const _Tp& __x, __false_type)
00189 {
00190 _ForwardIterator __cur = __first;
00191 try
00192 {
00193 for ( ; __n > 0; --__n, ++__cur)
00194 std::_Construct(&*__cur, __x);
00195 return __cur;
00196 }
00197 catch(...)
00198 {
00199 std::_Destroy(__first, __cur);
00200 __throw_exception_again;
00201 }
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 template<typename _ForwardIterator, typename _Size, typename _Tp>
00214 inline _ForwardIterator
00215 uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
00216 {
00217 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
00218 typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD;
00219 return std::__uninitialized_fill_n_aux(__first, __n, __x, _Is_POD());
00220 }
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 template<typename _InputIterator1, typename _InputIterator2,
00231 typename _ForwardIterator>
00232 inline _ForwardIterator
00233 __uninitialized_copy_copy(_InputIterator1 __first1,
00234 _InputIterator1 __last1,
00235 _InputIterator2 __first2,
00236 _InputIterator2 __last2,
00237 _ForwardIterator __result)
00238 {
00239 _ForwardIterator __mid = std::uninitialized_copy(__first1, __last1,
00240 __result);
00241 try
00242 {
00243 return std::uninitialized_copy(__first2, __last2, __mid);
00244 }
00245 catch(...)
00246 {
00247 std::_Destroy(__result, __mid);
00248 __throw_exception_again;
00249 }
00250 }
00251
00252
00253
00254
00255 template<typename _ForwardIterator, typename _Tp, typename _InputIterator>
00256 inline _ForwardIterator
00257 __uninitialized_fill_copy(_ForwardIterator __result, _ForwardIterator __mid,
00258 const _Tp& __x, _InputIterator __first,
00259 _InputIterator __last)
00260 {
00261 std::uninitialized_fill(__result, __mid, __x);
00262 try
00263 {
00264 return std::uninitialized_copy(__first, __last, __mid);
00265 }
00266 catch(...)
00267 {
00268 std::_Destroy(__result, __mid);
00269 __throw_exception_again;
00270 }
00271 }
00272
00273
00274
00275
00276 template<typename _InputIterator, typename _ForwardIterator, typename _Tp>
00277 inline void
00278 __uninitialized_copy_fill(_InputIterator __first1, _InputIterator __last1,
00279 _ForwardIterator __first2,
00280 _ForwardIterator __last2, const _Tp& __x)
00281 {
00282 _ForwardIterator __mid2 = std::uninitialized_copy(__first1, __last1,
00283 __first2);
00284 try
00285 {
00286 std::uninitialized_fill(__mid2, __last2, __x);
00287 }
00288 catch(...)
00289 {
00290 std::_Destroy(__first2, __mid2);
00291 __throw_exception_again;
00292 }
00293 }
00294
00295 }
00296
00297 #endif